<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>dom.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_dom_dom.js.html">dom.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Utilities for manipulating the browser&#39;s Document Object Model
<a name="line17"></a> * Inspiration taken *heavily* from mochikit (http://mochikit.com/).
<a name="line18"></a> *
<a name="line19"></a> * You can use {@link goog.dom.DomHelper} to create new dom helpers that refer
<a name="line20"></a> * to a different document object.  This is useful if you are working with
<a name="line21"></a> * frames or multiple windows.
<a name="line22"></a> *
<a name="line23"></a> */
<a name="line24"></a>
<a name="line25"></a>
<a name="line26"></a>// TODO(arv): Rename/refactor getTextContent and getRawTextContent. The problem
<a name="line27"></a>// is that getTextContent should mimic the DOM3 textContent. We should add a
<a name="line28"></a>// getInnerText (or getText) which tries to return the visible text, innerText.
<a name="line29"></a>
<a name="line30"></a>
<a name="line31"></a>goog.provide(&#39;goog.dom&#39;);
<a name="line32"></a>goog.provide(&#39;goog.dom.DomHelper&#39;);
<a name="line33"></a>goog.provide(&#39;goog.dom.NodeType&#39;);
<a name="line34"></a>
<a name="line35"></a>goog.require(&#39;goog.array&#39;);
<a name="line36"></a>goog.require(&#39;goog.dom.BrowserFeature&#39;);
<a name="line37"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line38"></a>goog.require(&#39;goog.dom.classes&#39;);
<a name="line39"></a>goog.require(&#39;goog.math.Coordinate&#39;);
<a name="line40"></a>goog.require(&#39;goog.math.Size&#39;);
<a name="line41"></a>goog.require(&#39;goog.object&#39;);
<a name="line42"></a>goog.require(&#39;goog.string&#39;);
<a name="line43"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line44"></a>
<a name="line45"></a>
<a name="line46"></a>/**
<a name="line47"></a> * @define {boolean} Whether we know at compile time that the browser is in
<a name="line48"></a> * quirks mode.
<a name="line49"></a> */
<a name="line50"></a>goog.dom.ASSUME_QUIRKS_MODE = false;
<a name="line51"></a>
<a name="line52"></a>
<a name="line53"></a>/**
<a name="line54"></a> * @define {boolean} Whether we know at compile time that the browser is in
<a name="line55"></a> * standards compliance mode.
<a name="line56"></a> */
<a name="line57"></a>goog.dom.ASSUME_STANDARDS_MODE = false;
<a name="line58"></a>
<a name="line59"></a>
<a name="line60"></a>/**
<a name="line61"></a> * Whether we know the compatibility mode at compile time.
<a name="line62"></a> * @type {boolean}
<a name="line63"></a> * @private
<a name="line64"></a> */
<a name="line65"></a>goog.dom.COMPAT_MODE_KNOWN_ =
<a name="line66"></a>    goog.dom.ASSUME_QUIRKS_MODE || goog.dom.ASSUME_STANDARDS_MODE;
<a name="line67"></a>
<a name="line68"></a>
<a name="line69"></a>/**
<a name="line70"></a> * Enumeration for DOM node types (for reference)
<a name="line71"></a> * @enum {number}
<a name="line72"></a> */
<a name="line73"></a>goog.dom.NodeType = {
<a name="line74"></a>  ELEMENT: 1,
<a name="line75"></a>  ATTRIBUTE: 2,
<a name="line76"></a>  TEXT: 3,
<a name="line77"></a>  CDATA_SECTION: 4,
<a name="line78"></a>  ENTITY_REFERENCE: 5,
<a name="line79"></a>  ENTITY: 6,
<a name="line80"></a>  PROCESSING_INSTRUCTION: 7,
<a name="line81"></a>  COMMENT: 8,
<a name="line82"></a>  DOCUMENT: 9,
<a name="line83"></a>  DOCUMENT_TYPE: 10,
<a name="line84"></a>  DOCUMENT_FRAGMENT: 11,
<a name="line85"></a>  NOTATION: 12
<a name="line86"></a>};
<a name="line87"></a>
<a name="line88"></a>
<a name="line89"></a>/**
<a name="line90"></a> * Gets the DomHelper object for the document where the element resides.
<a name="line91"></a> * @param {(Node|Window)=} opt_element If present, gets the DomHelper for this
<a name="line92"></a> *     element.
<a name="line93"></a> * @return {!goog.dom.DomHelper} The DomHelper.
<a name="line94"></a> */
<a name="line95"></a>goog.dom.getDomHelper = function(opt_element) {
<a name="line96"></a>  return opt_element ?
<a name="line97"></a>      new goog.dom.DomHelper(goog.dom.getOwnerDocument(opt_element)) :
<a name="line98"></a>      (goog.dom.defaultDomHelper_ ||
<a name="line99"></a>          (goog.dom.defaultDomHelper_ = new goog.dom.DomHelper()));
<a name="line100"></a>};
<a name="line101"></a>
<a name="line102"></a>
<a name="line103"></a>/**
<a name="line104"></a> * Cached default DOM helper.
<a name="line105"></a> * @type {goog.dom.DomHelper}
<a name="line106"></a> * @private
<a name="line107"></a> */
<a name="line108"></a>goog.dom.defaultDomHelper_;
<a name="line109"></a>
<a name="line110"></a>
<a name="line111"></a>/**
<a name="line112"></a> * Gets the document object being used by the dom library.
<a name="line113"></a> * @return {!Document} Document object.
<a name="line114"></a> */
<a name="line115"></a>goog.dom.getDocument = function() {
<a name="line116"></a>  return document;
<a name="line117"></a>};
<a name="line118"></a>
<a name="line119"></a>
<a name="line120"></a>/**
<a name="line121"></a> * Alias for getElementById. If a DOM node is passed in then we just return
<a name="line122"></a> * that.
<a name="line123"></a> * @param {string|Element} element Element ID or a DOM node.
<a name="line124"></a> * @return {Element} The element with the given ID, or the node passed in.
<a name="line125"></a> */
<a name="line126"></a>goog.dom.getElement = function(element) {
<a name="line127"></a>  return goog.isString(element) ?
<a name="line128"></a>      document.getElementById(element) : element;
<a name="line129"></a>};
<a name="line130"></a>
<a name="line131"></a>
<a name="line132"></a>/**
<a name="line133"></a> * Alias for getElement.
<a name="line134"></a> * @param {string|Element} element Element ID or a DOM node.
<a name="line135"></a> * @return {Element} The element with the given ID, or the node passed in.
<a name="line136"></a> * @deprecated Use {@link goog.dom.getElement} instead.
<a name="line137"></a> */
<a name="line138"></a>goog.dom.$ = goog.dom.getElement;
<a name="line139"></a>
<a name="line140"></a>
<a name="line141"></a>/**
<a name="line142"></a> * Looks up elements by both tag and class name, using browser native functions
<a name="line143"></a> * ({@code querySelectorAll}, {@code getElementsByTagName} or
<a name="line144"></a> * {@code getElementsByClassName}) where possible. This function
<a name="line145"></a> * is a useful, if limited, way of collecting a list of DOM elements
<a name="line146"></a> * with certain characteristics.  {@code goog.dom.query} offers a
<a name="line147"></a> * more powerful and general solution which allows matching on CSS3
<a name="line148"></a> * selector expressions, but at increased cost in code size. If all you
<a name="line149"></a> * need is particular tags belonging to a single class, this function
<a name="line150"></a> * is fast and sleek.
<a name="line151"></a> *
<a name="line152"></a> * @see {goog.dom.query}
<a name="line153"></a> *
<a name="line154"></a> * @param {?string=} opt_tag Element tag name.
<a name="line155"></a> * @param {?string=} opt_class Optional class name.
<a name="line156"></a> * @param {(Document|Element)=} opt_el Optional element to look in.
<a name="line157"></a> * @return { {length: number} } Array-like list of elements (only a length
<a name="line158"></a> *     property and numerical indices are guaranteed to exist).
<a name="line159"></a> */
<a name="line160"></a>goog.dom.getElementsByTagNameAndClass = function(opt_tag, opt_class, opt_el) {
<a name="line161"></a>  return goog.dom.getElementsByTagNameAndClass_(document, opt_tag, opt_class,
<a name="line162"></a>                                                opt_el);
<a name="line163"></a>};
<a name="line164"></a>
<a name="line165"></a>
<a name="line166"></a>/**
<a name="line167"></a> * Returns an array of all the elements with the provided className.
<a name="line168"></a> * @see {goog.dom.query}
<a name="line169"></a> * @param {string} className the name of the class to look for.
<a name="line170"></a> * @param {(Document|Element)=} opt_el Optional element to look in.
<a name="line171"></a> * @return { {length: number} } The items found with the class name provided.
<a name="line172"></a> */
<a name="line173"></a>goog.dom.getElementsByClass = function(className, opt_el) {
<a name="line174"></a>  var parent = opt_el || document;
<a name="line175"></a>  if (goog.dom.canUseQuerySelector_(parent)) {
<a name="line176"></a>    return parent.querySelectorAll(&#39;.&#39; + className);
<a name="line177"></a>  } else if (parent.getElementsByClassName) {
<a name="line178"></a>    return parent.getElementsByClassName(className);
<a name="line179"></a>  }
<a name="line180"></a>  return goog.dom.getElementsByTagNameAndClass_(
<a name="line181"></a>      document, &#39;*&#39;, className, opt_el);
<a name="line182"></a>};
<a name="line183"></a>
<a name="line184"></a>
<a name="line185"></a>/**
<a name="line186"></a> * Returns the first element with the provided className.
<a name="line187"></a> * @see {goog.dom.query}
<a name="line188"></a> * @param {string} className the name of the class to look for.
<a name="line189"></a> * @param {Element|Document=} opt_el Optional element to look in.
<a name="line190"></a> * @return {Element} The first item with the class name provided.
<a name="line191"></a> */
<a name="line192"></a>goog.dom.getElementByClass = function(className, opt_el) {
<a name="line193"></a>  var parent = opt_el || document;
<a name="line194"></a>  var retVal = null;
<a name="line195"></a>  if (goog.dom.canUseQuerySelector_(parent)) {
<a name="line196"></a>    retVal = parent.querySelector(&#39;.&#39; + className);
<a name="line197"></a>  } else {
<a name="line198"></a>    retVal = goog.dom.getElementsByClass(className, opt_el)[0];
<a name="line199"></a>  }
<a name="line200"></a>  return retVal || null;
<a name="line201"></a>};
<a name="line202"></a>
<a name="line203"></a>
<a name="line204"></a>/**
<a name="line205"></a> * Prefer the standardized (http://www.w3.org/TR/selectors-api/), native and
<a name="line206"></a> * fast W3C Selectors API.
<a name="line207"></a> * @param {!(Element|Document)} parent The parent document object.
<a name="line208"></a> * @return {boolean} whether or not we can use parent.querySelector* APIs.
<a name="line209"></a> * @private
<a name="line210"></a> */
<a name="line211"></a>goog.dom.canUseQuerySelector_ = function(parent) {
<a name="line212"></a>  return !!(parent.querySelectorAll &amp;&amp; parent.querySelector);
<a name="line213"></a>};
<a name="line214"></a>
<a name="line215"></a>
<a name="line216"></a>/**
<a name="line217"></a> * Helper for {@code getElementsByTagNameAndClass}.
<a name="line218"></a> * @param {!Document} doc The document to get the elements in.
<a name="line219"></a> * @param {?string=} opt_tag Element tag name.
<a name="line220"></a> * @param {?string=} opt_class Optional class name.
<a name="line221"></a> * @param {(Document|Element)=} opt_el Optional element to look in.
<a name="line222"></a> * @return { {length: number} } Array-like list of elements (only a length
<a name="line223"></a> *     property and numerical indices are guaranteed to exist).
<a name="line224"></a> * @private
<a name="line225"></a> */
<a name="line226"></a>goog.dom.getElementsByTagNameAndClass_ = function(doc, opt_tag, opt_class,
<a name="line227"></a>                                                  opt_el) {
<a name="line228"></a>  var parent = opt_el || doc;
<a name="line229"></a>  var tagName = (opt_tag &amp;&amp; opt_tag != &#39;*&#39;) ? opt_tag.toUpperCase() : &#39;&#39;;
<a name="line230"></a>
<a name="line231"></a>  if (goog.dom.canUseQuerySelector_(parent) &amp;&amp;
<a name="line232"></a>      (tagName || opt_class)) {
<a name="line233"></a>    var query = tagName + (opt_class ? &#39;.&#39; + opt_class : &#39;&#39;);
<a name="line234"></a>    return parent.querySelectorAll(query);
<a name="line235"></a>  }
<a name="line236"></a>
<a name="line237"></a>  // Use the native getElementsByClassName if available, under the assumption
<a name="line238"></a>  // that even when the tag name is specified, there will be fewer elements to
<a name="line239"></a>  // filter through when going by class than by tag name
<a name="line240"></a>  if (opt_class &amp;&amp; parent.getElementsByClassName) {
<a name="line241"></a>    var els = parent.getElementsByClassName(opt_class);
<a name="line242"></a>
<a name="line243"></a>    if (tagName) {
<a name="line244"></a>      var arrayLike = {};
<a name="line245"></a>      var len = 0;
<a name="line246"></a>
<a name="line247"></a>      // Filter for specific tags if requested.
<a name="line248"></a>      for (var i = 0, el; el = els[i]; i++) {
<a name="line249"></a>        if (tagName == el.nodeName) {
<a name="line250"></a>          arrayLike[len++] = el;
<a name="line251"></a>        }
<a name="line252"></a>      }
<a name="line253"></a>      arrayLike.length = len;
<a name="line254"></a>
<a name="line255"></a>      return arrayLike;
<a name="line256"></a>    } else {
<a name="line257"></a>      return els;
<a name="line258"></a>    }
<a name="line259"></a>  }
<a name="line260"></a>
<a name="line261"></a>  var els = parent.getElementsByTagName(tagName || &#39;*&#39;);
<a name="line262"></a>
<a name="line263"></a>  if (opt_class) {
<a name="line264"></a>    var arrayLike = {};
<a name="line265"></a>    var len = 0;
<a name="line266"></a>    for (var i = 0, el; el = els[i]; i++) {
<a name="line267"></a>      var className = el.className;
<a name="line268"></a>      // Check if className has a split function since SVG className does not.
<a name="line269"></a>      if (typeof className.split == &#39;function&#39; &amp;&amp;
<a name="line270"></a>          goog.array.contains(className.split(/\s+/), opt_class)) {
<a name="line271"></a>        arrayLike[len++] = el;
<a name="line272"></a>      }
<a name="line273"></a>    }
<a name="line274"></a>    arrayLike.length = len;
<a name="line275"></a>    return arrayLike;
<a name="line276"></a>  } else {
<a name="line277"></a>    return els;
<a name="line278"></a>  }
<a name="line279"></a>};
<a name="line280"></a>
<a name="line281"></a>
<a name="line282"></a>/**
<a name="line283"></a> * Alias for {@code getElementsByTagNameAndClass}.
<a name="line284"></a> * @param {?string=} opt_tag Element tag name.
<a name="line285"></a> * @param {?string=} opt_class Optional class name.
<a name="line286"></a> * @param {Element=} opt_el Optional element to look in.
<a name="line287"></a> * @return { {length: number} } Array-like list of elements (only a length
<a name="line288"></a> *     property and numerical indices are guaranteed to exist).
<a name="line289"></a> * @deprecated Use {@link goog.dom.getElementsByTagNameAndClass} instead.
<a name="line290"></a> */
<a name="line291"></a>goog.dom.$$ = goog.dom.getElementsByTagNameAndClass;
<a name="line292"></a>
<a name="line293"></a>
<a name="line294"></a>/**
<a name="line295"></a> * Sets multiple properties on a node.
<a name="line296"></a> * @param {Element} element DOM node to set properties on.
<a name="line297"></a> * @param {Object} properties Hash of property:value pairs.
<a name="line298"></a> */
<a name="line299"></a>goog.dom.setProperties = function(element, properties) {
<a name="line300"></a>  goog.object.forEach(properties, function(val, key) {
<a name="line301"></a>    if (key == &#39;style&#39;) {
<a name="line302"></a>      element.style.cssText = val;
<a name="line303"></a>    } else if (key == &#39;class&#39;) {
<a name="line304"></a>      element.className = val;
<a name="line305"></a>    } else if (key == &#39;for&#39;) {
<a name="line306"></a>      element.htmlFor = val;
<a name="line307"></a>    } else if (key in goog.dom.DIRECT_ATTRIBUTE_MAP_) {
<a name="line308"></a>      element.setAttribute(goog.dom.DIRECT_ATTRIBUTE_MAP_[key], val);
<a name="line309"></a>    } else if (goog.string.startsWith(key, &#39;aria-&#39;) ||
<a name="line310"></a>        goog.string.startsWith(key, &#39;data-&#39;)) {
<a name="line311"></a>      element.setAttribute(key, val);
<a name="line312"></a>    } else {
<a name="line313"></a>      element[key] = val;
<a name="line314"></a>    }
<a name="line315"></a>  });
<a name="line316"></a>};
<a name="line317"></a>
<a name="line318"></a>
<a name="line319"></a>/**
<a name="line320"></a> * Map of attributes that should be set using
<a name="line321"></a> * element.setAttribute(key, val) instead of element[key] = val.  Used
<a name="line322"></a> * by goog.dom.setProperties.
<a name="line323"></a> *
<a name="line324"></a> * @type {Object}
<a name="line325"></a> * @private
<a name="line326"></a> */
<a name="line327"></a>goog.dom.DIRECT_ATTRIBUTE_MAP_ = {
<a name="line328"></a>  &#39;cellpadding&#39;: &#39;cellPadding&#39;,
<a name="line329"></a>  &#39;cellspacing&#39;: &#39;cellSpacing&#39;,
<a name="line330"></a>  &#39;colspan&#39;: &#39;colSpan&#39;,
<a name="line331"></a>  &#39;frameborder&#39;: &#39;frameBorder&#39;,
<a name="line332"></a>  &#39;height&#39;: &#39;height&#39;,
<a name="line333"></a>  &#39;maxlength&#39;: &#39;maxLength&#39;,
<a name="line334"></a>  &#39;role&#39;: &#39;role&#39;,
<a name="line335"></a>  &#39;rowspan&#39;: &#39;rowSpan&#39;,
<a name="line336"></a>  &#39;type&#39;: &#39;type&#39;,
<a name="line337"></a>  &#39;usemap&#39;: &#39;useMap&#39;,
<a name="line338"></a>  &#39;valign&#39;: &#39;vAlign&#39;,
<a name="line339"></a>  &#39;width&#39;: &#39;width&#39;
<a name="line340"></a>};
<a name="line341"></a>
<a name="line342"></a>
<a name="line343"></a>/**
<a name="line344"></a> * Gets the dimensions of the viewport.
<a name="line345"></a> *
<a name="line346"></a> * Gecko Standards mode:
<a name="line347"></a> * docEl.clientWidth  Width of viewport excluding scrollbar.
<a name="line348"></a> * win.innerWidth     Width of viewport including scrollbar.
<a name="line349"></a> * body.clientWidth   Width of body element.
<a name="line350"></a> *
<a name="line351"></a> * docEl.clientHeight Height of viewport excluding scrollbar.
<a name="line352"></a> * win.innerHeight    Height of viewport including scrollbar.
<a name="line353"></a> * body.clientHeight  Height of document.
<a name="line354"></a> *
<a name="line355"></a> * Gecko Backwards compatible mode:
<a name="line356"></a> * docEl.clientWidth  Width of viewport excluding scrollbar.
<a name="line357"></a> * win.innerWidth     Width of viewport including scrollbar.
<a name="line358"></a> * body.clientWidth   Width of viewport excluding scrollbar.
<a name="line359"></a> *
<a name="line360"></a> * docEl.clientHeight Height of document.
<a name="line361"></a> * win.innerHeight    Height of viewport including scrollbar.
<a name="line362"></a> * body.clientHeight  Height of viewport excluding scrollbar.
<a name="line363"></a> *
<a name="line364"></a> * IE6/7 Standards mode:
<a name="line365"></a> * docEl.clientWidth  Width of viewport excluding scrollbar.
<a name="line366"></a> * win.innerWidth     Undefined.
<a name="line367"></a> * body.clientWidth   Width of body element.
<a name="line368"></a> *
<a name="line369"></a> * docEl.clientHeight Height of viewport excluding scrollbar.
<a name="line370"></a> * win.innerHeight    Undefined.
<a name="line371"></a> * body.clientHeight  Height of document element.
<a name="line372"></a> *
<a name="line373"></a> * IE5 + IE6/7 Backwards compatible mode:
<a name="line374"></a> * docEl.clientWidth  0.
<a name="line375"></a> * win.innerWidth     Undefined.
<a name="line376"></a> * body.clientWidth   Width of viewport excluding scrollbar.
<a name="line377"></a> *
<a name="line378"></a> * docEl.clientHeight 0.
<a name="line379"></a> * win.innerHeight    Undefined.
<a name="line380"></a> * body.clientHeight  Height of viewport excluding scrollbar.
<a name="line381"></a> *
<a name="line382"></a> * Opera 9 Standards and backwards compatible mode:
<a name="line383"></a> * docEl.clientWidth  Width of viewport excluding scrollbar.
<a name="line384"></a> * win.innerWidth     Width of viewport including scrollbar.
<a name="line385"></a> * body.clientWidth   Width of viewport excluding scrollbar.
<a name="line386"></a> *
<a name="line387"></a> * docEl.clientHeight Height of document.
<a name="line388"></a> * win.innerHeight    Height of viewport including scrollbar.
<a name="line389"></a> * body.clientHeight  Height of viewport excluding scrollbar.
<a name="line390"></a> *
<a name="line391"></a> * WebKit:
<a name="line392"></a> * Safari 2
<a name="line393"></a> * docEl.clientHeight Same as scrollHeight.
<a name="line394"></a> * docEl.clientWidth  Same as innerWidth.
<a name="line395"></a> * win.innerWidth     Width of viewport excluding scrollbar.
<a name="line396"></a> * win.innerHeight    Height of the viewport including scrollbar.
<a name="line397"></a> * frame.innerHeight  Height of the viewport exluding scrollbar.
<a name="line398"></a> *
<a name="line399"></a> * Safari 3 (tested in 522)
<a name="line400"></a> *
<a name="line401"></a> * docEl.clientWidth  Width of viewport excluding scrollbar.
<a name="line402"></a> * docEl.clientHeight Height of viewport excluding scrollbar in strict mode.
<a name="line403"></a> * body.clientHeight  Height of viewport excluding scrollbar in quirks mode.
<a name="line404"></a> *
<a name="line405"></a> * @param {Window=} opt_window Optional window element to test.
<a name="line406"></a> * @return {!goog.math.Size} Object with values &#39;width&#39; and &#39;height&#39;.
<a name="line407"></a> */
<a name="line408"></a>goog.dom.getViewportSize = function(opt_window) {
<a name="line409"></a>  // TODO(arv): This should not take an argument
<a name="line410"></a>  return goog.dom.getViewportSize_(opt_window || window);
<a name="line411"></a>};
<a name="line412"></a>
<a name="line413"></a>
<a name="line414"></a>/**
<a name="line415"></a> * Helper for {@code getViewportSize}.
<a name="line416"></a> * @param {Window} win The window to get the view port size for.
<a name="line417"></a> * @return {!goog.math.Size} Object with values &#39;width&#39; and &#39;height&#39;.
<a name="line418"></a> * @private
<a name="line419"></a> */
<a name="line420"></a>goog.dom.getViewportSize_ = function(win) {
<a name="line421"></a>  var doc = win.document;
<a name="line422"></a>  var el = goog.dom.isCss1CompatMode_(doc) ? doc.documentElement : doc.body;
<a name="line423"></a>  return new goog.math.Size(el.clientWidth, el.clientHeight);
<a name="line424"></a>};
<a name="line425"></a>
<a name="line426"></a>
<a name="line427"></a>/**
<a name="line428"></a> * Calculates the height of the document.
<a name="line429"></a> *
<a name="line430"></a> * @return {number} The height of the current document.
<a name="line431"></a> */
<a name="line432"></a>goog.dom.getDocumentHeight = function() {
<a name="line433"></a>  return goog.dom.getDocumentHeight_(window);
<a name="line434"></a>};
<a name="line435"></a>
<a name="line436"></a>
<a name="line437"></a>/**
<a name="line438"></a> * Calculates the height of the document of the given window.
<a name="line439"></a> *
<a name="line440"></a> * Function code copied from the opensocial gadget api:
<a name="line441"></a> *   gadgets.window.adjustHeight(opt_height)
<a name="line442"></a> *
<a name="line443"></a> * @private
<a name="line444"></a> * @param {Window} win The window whose document height to retrieve.
<a name="line445"></a> * @return {number} The height of the document of the given window.
<a name="line446"></a> */
<a name="line447"></a>goog.dom.getDocumentHeight_ = function(win) {
<a name="line448"></a>  // NOTE(eae): This method will return the window size rather than the document
<a name="line449"></a>  // size in webkit quirks mode.
<a name="line450"></a>  var doc = win.document;
<a name="line451"></a>  var height = 0;
<a name="line452"></a>
<a name="line453"></a>  if (doc) {
<a name="line454"></a>    // Calculating inner content height is hard and different between
<a name="line455"></a>    // browsers rendering in Strict vs. Quirks mode.  We use a combination of
<a name="line456"></a>    // three properties within document.body and document.documentElement:
<a name="line457"></a>    // - scrollHeight
<a name="line458"></a>    // - offsetHeight
<a name="line459"></a>    // - clientHeight
<a name="line460"></a>    // These values differ significantly between browsers and rendering modes.
<a name="line461"></a>    // But there are patterns.  It just takes a lot of time and persistence
<a name="line462"></a>    // to figure out.
<a name="line463"></a>
<a name="line464"></a>    // Get the height of the viewport
<a name="line465"></a>    var vh = goog.dom.getViewportSize_(win).height;
<a name="line466"></a>    var body = doc.body;
<a name="line467"></a>    var docEl = doc.documentElement;
<a name="line468"></a>    if (goog.dom.isCss1CompatMode_(doc) &amp;&amp; docEl.scrollHeight) {
<a name="line469"></a>      // In Strict mode:
<a name="line470"></a>      // The inner content height is contained in either:
<a name="line471"></a>      //    document.documentElement.scrollHeight
<a name="line472"></a>      //    document.documentElement.offsetHeight
<a name="line473"></a>      // Based on studying the values output by different browsers,
<a name="line474"></a>      // use the value that&#39;s NOT equal to the viewport height found above.
<a name="line475"></a>      height = docEl.scrollHeight != vh ?
<a name="line476"></a>          docEl.scrollHeight : docEl.offsetHeight;
<a name="line477"></a>    } else {
<a name="line478"></a>      // In Quirks mode:
<a name="line479"></a>      // documentElement.clientHeight is equal to documentElement.offsetHeight
<a name="line480"></a>      // except in IE.  In most browsers, document.documentElement can be used
<a name="line481"></a>      // to calculate the inner content height.
<a name="line482"></a>      // However, in other browsers (e.g. IE), document.body must be used
<a name="line483"></a>      // instead.  How do we know which one to use?
<a name="line484"></a>      // If document.documentElement.clientHeight does NOT equal
<a name="line485"></a>      // document.documentElement.offsetHeight, then use document.body.
<a name="line486"></a>      var sh = docEl.scrollHeight;
<a name="line487"></a>      var oh = docEl.offsetHeight;
<a name="line488"></a>      if (docEl.clientHeight != oh) {
<a name="line489"></a>        sh = body.scrollHeight;
<a name="line490"></a>        oh = body.offsetHeight;
<a name="line491"></a>      }
<a name="line492"></a>
<a name="line493"></a>      // Detect whether the inner content height is bigger or smaller
<a name="line494"></a>      // than the bounding box (viewport).  If bigger, take the larger
<a name="line495"></a>      // value.  If smaller, take the smaller value.
<a name="line496"></a>      if (sh &gt; vh) {
<a name="line497"></a>        // Content is larger
<a name="line498"></a>        height = sh &gt; oh ? sh : oh;
<a name="line499"></a>      } else {
<a name="line500"></a>        // Content is smaller
<a name="line501"></a>        height = sh &lt; oh ? sh : oh;
<a name="line502"></a>      }
<a name="line503"></a>    }
<a name="line504"></a>  }
<a name="line505"></a>
<a name="line506"></a>  return height;
<a name="line507"></a>};
<a name="line508"></a>
<a name="line509"></a>
<a name="line510"></a>/**
<a name="line511"></a> * Gets the page scroll distance as a coordinate object.
<a name="line512"></a> *
<a name="line513"></a> * @param {Window=} opt_window Optional window element to test.
<a name="line514"></a> * @return {!goog.math.Coordinate} Object with values &#39;x&#39; and &#39;y&#39;.
<a name="line515"></a> * @deprecated Use {@link goog.dom.getDocumentScroll} instead.
<a name="line516"></a> */
<a name="line517"></a>goog.dom.getPageScroll = function(opt_window) {
<a name="line518"></a>  var win = opt_window || goog.global || window;
<a name="line519"></a>  return goog.dom.getDomHelper(win.document).getDocumentScroll();
<a name="line520"></a>};
<a name="line521"></a>
<a name="line522"></a>
<a name="line523"></a>/**
<a name="line524"></a> * Gets the document scroll distance as a coordinate object.
<a name="line525"></a> *
<a name="line526"></a> * @return {!goog.math.Coordinate} Object with values &#39;x&#39; and &#39;y&#39;.
<a name="line527"></a> */
<a name="line528"></a>goog.dom.getDocumentScroll = function() {
<a name="line529"></a>  return goog.dom.getDocumentScroll_(document);
<a name="line530"></a>};
<a name="line531"></a>
<a name="line532"></a>
<a name="line533"></a>/**
<a name="line534"></a> * Helper for {@code getDocumentScroll}.
<a name="line535"></a> *
<a name="line536"></a> * @param {!Document} doc The document to get the scroll for.
<a name="line537"></a> * @return {!goog.math.Coordinate} Object with values &#39;x&#39; and &#39;y&#39;.
<a name="line538"></a> * @private
<a name="line539"></a> */
<a name="line540"></a>goog.dom.getDocumentScroll_ = function(doc) {
<a name="line541"></a>  var el = goog.dom.getDocumentScrollElement_(doc);
<a name="line542"></a>  var win = goog.dom.getWindow_(doc);
<a name="line543"></a>  return new goog.math.Coordinate(win.pageXOffset || el.scrollLeft,
<a name="line544"></a>      win.pageYOffset || el.scrollTop);
<a name="line545"></a>};
<a name="line546"></a>
<a name="line547"></a>
<a name="line548"></a>/**
<a name="line549"></a> * Gets the document scroll element.
<a name="line550"></a> * @return {Element} Scrolling element.
<a name="line551"></a> */
<a name="line552"></a>goog.dom.getDocumentScrollElement = function() {
<a name="line553"></a>  return goog.dom.getDocumentScrollElement_(document);
<a name="line554"></a>};
<a name="line555"></a>
<a name="line556"></a>
<a name="line557"></a>/**
<a name="line558"></a> * Helper for {@code getDocumentScrollElement}.
<a name="line559"></a> * @param {!Document} doc The document to get the scroll element for.
<a name="line560"></a> * @return {Element} Scrolling element.
<a name="line561"></a> * @private
<a name="line562"></a> */
<a name="line563"></a>goog.dom.getDocumentScrollElement_ = function(doc) {
<a name="line564"></a>  // Safari (2 and 3) needs body.scrollLeft in both quirks mode and strict mode.
<a name="line565"></a>  return !goog.userAgent.WEBKIT &amp;&amp; goog.dom.isCss1CompatMode_(doc) ?
<a name="line566"></a>      doc.documentElement : doc.body;
<a name="line567"></a>};
<a name="line568"></a>
<a name="line569"></a>
<a name="line570"></a>/**
<a name="line571"></a> * Gets the window object associated with the given document.
<a name="line572"></a> *
<a name="line573"></a> * @param {Document=} opt_doc  Document object to get window for.
<a name="line574"></a> * @return {!Window} The window associated with the given document.
<a name="line575"></a> */
<a name="line576"></a>goog.dom.getWindow = function(opt_doc) {
<a name="line577"></a>  // TODO(arv): This should not take an argument.
<a name="line578"></a>  return opt_doc ? goog.dom.getWindow_(opt_doc) : window;
<a name="line579"></a>};
<a name="line580"></a>
<a name="line581"></a>
<a name="line582"></a>/**
<a name="line583"></a> * Helper for {@code getWindow}.
<a name="line584"></a> *
<a name="line585"></a> * @param {!Document} doc  Document object to get window for.
<a name="line586"></a> * @return {!Window} The window associated with the given document.
<a name="line587"></a> * @private
<a name="line588"></a> */
<a name="line589"></a>goog.dom.getWindow_ = function(doc) {
<a name="line590"></a>  return doc.parentWindow || doc.defaultView;
<a name="line591"></a>};
<a name="line592"></a>
<a name="line593"></a>
<a name="line594"></a>/**
<a name="line595"></a> * Returns a dom node with a set of attributes.  This function accepts varargs
<a name="line596"></a> * for subsequent nodes to be added.  Subsequent nodes will be added to the
<a name="line597"></a> * first node as childNodes.
<a name="line598"></a> *
<a name="line599"></a> * So:
<a name="line600"></a> * &lt;code&gt;createDom(&#39;div&#39;, null, createDom(&#39;p&#39;), createDom(&#39;p&#39;));&lt;/code&gt;
<a name="line601"></a> * would return a div with two child paragraphs
<a name="line602"></a> *
<a name="line603"></a> * @param {string} tagName Tag to create.
<a name="line604"></a> * @param {(Object|Array.&lt;string&gt;|string)=} opt_attributes If object, then a map
<a name="line605"></a> *     of name-value pairs for attributes. If a string, then this is the
<a name="line606"></a> *     className of the new element. If an array, the elements will be joined
<a name="line607"></a> *     together as the className of the new element.
<a name="line608"></a> * @param {...(Object|string|Array|NodeList)} var_args Further DOM nodes or
<a name="line609"></a> *     strings for text nodes. If one of the var_args is an array or NodeList,i
<a name="line610"></a> *     its elements will be added as childNodes instead.
<a name="line611"></a> * @return {!Element} Reference to a DOM node.
<a name="line612"></a> */
<a name="line613"></a>goog.dom.createDom = function(tagName, opt_attributes, var_args) {
<a name="line614"></a>  return goog.dom.createDom_(document, arguments);
<a name="line615"></a>};
<a name="line616"></a>
<a name="line617"></a>
<a name="line618"></a>/**
<a name="line619"></a> * Helper for {@code createDom}.
<a name="line620"></a> * @param {!Document} doc The document to create the DOM in.
<a name="line621"></a> * @param {!Arguments} args Argument object passed from the callers. See
<a name="line622"></a> *     {@code goog.dom.createDom} for details.
<a name="line623"></a> * @return {!Element} Reference to a DOM node.
<a name="line624"></a> * @private
<a name="line625"></a> */
<a name="line626"></a>goog.dom.createDom_ = function(doc, args) {
<a name="line627"></a>  var tagName = args[0];
<a name="line628"></a>  var attributes = args[1];
<a name="line629"></a>
<a name="line630"></a>  // Internet Explorer is dumb: http://msdn.microsoft.com/workshop/author/
<a name="line631"></a>  //                            dhtml/reference/properties/name_2.asp
<a name="line632"></a>  // Also does not allow setting of &#39;type&#39; attribute on &#39;input&#39; or &#39;button&#39;.
<a name="line633"></a>  if (!goog.dom.BrowserFeature.CAN_ADD_NAME_OR_TYPE_ATTRIBUTES &amp;&amp; attributes &amp;&amp;
<a name="line634"></a>      (attributes.name || attributes.type)) {
<a name="line635"></a>    var tagNameArr = [&#39;&lt;&#39;, tagName];
<a name="line636"></a>    if (attributes.name) {
<a name="line637"></a>      tagNameArr.push(&#39; name=&quot;&#39;, goog.string.htmlEscape(attributes.name),
<a name="line638"></a>                      &#39;&quot;&#39;);
<a name="line639"></a>    }
<a name="line640"></a>    if (attributes.type) {
<a name="line641"></a>      tagNameArr.push(&#39; type=&quot;&#39;, goog.string.htmlEscape(attributes.type),
<a name="line642"></a>                      &#39;&quot;&#39;);
<a name="line643"></a>
<a name="line644"></a>      // Clone attributes map to remove &#39;type&#39; without mutating the input.
<a name="line645"></a>      var clone = {};
<a name="line646"></a>      goog.object.extend(clone, attributes);
<a name="line647"></a>
<a name="line648"></a>      // JSCompiler can&#39;t see how goog.object.extend added this property,
<a name="line649"></a>      // because it was essentially added by reflection.
<a name="line650"></a>      // So it needs to be quoted.
<a name="line651"></a>      delete clone[&#39;type&#39;];
<a name="line652"></a>
<a name="line653"></a>      attributes = clone;
<a name="line654"></a>    }
<a name="line655"></a>    tagNameArr.push(&#39;&gt;&#39;);
<a name="line656"></a>    tagName = tagNameArr.join(&#39;&#39;);
<a name="line657"></a>  }
<a name="line658"></a>
<a name="line659"></a>  var element = doc.createElement(tagName);
<a name="line660"></a>
<a name="line661"></a>  if (attributes) {
<a name="line662"></a>    if (goog.isString(attributes)) {
<a name="line663"></a>      element.className = attributes;
<a name="line664"></a>    } else if (goog.isArray(attributes)) {
<a name="line665"></a>      goog.dom.classes.add.apply(null, [element].concat(attributes));
<a name="line666"></a>    } else {
<a name="line667"></a>      goog.dom.setProperties(element, attributes);
<a name="line668"></a>    }
<a name="line669"></a>  }
<a name="line670"></a>
<a name="line671"></a>  if (args.length &gt; 2) {
<a name="line672"></a>    goog.dom.append_(doc, element, args, 2);
<a name="line673"></a>  }
<a name="line674"></a>
<a name="line675"></a>  return element;
<a name="line676"></a>};
<a name="line677"></a>
<a name="line678"></a>
<a name="line679"></a>/**
<a name="line680"></a> * Appends a node with text or other nodes.
<a name="line681"></a> * @param {!Document} doc The document to create new nodes in.
<a name="line682"></a> * @param {!Node} parent The node to append nodes to.
<a name="line683"></a> * @param {!Arguments} args The values to add. See {@code goog.dom.append}.
<a name="line684"></a> * @param {number} startIndex The index of the array to start from.
<a name="line685"></a> * @private
<a name="line686"></a> */
<a name="line687"></a>goog.dom.append_ = function(doc, parent, args, startIndex) {
<a name="line688"></a>  function childHandler(child) {
<a name="line689"></a>    // TODO(user): More coercion, ala MochiKit?
<a name="line690"></a>    if (child) {
<a name="line691"></a>      parent.appendChild(goog.isString(child) ?
<a name="line692"></a>          doc.createTextNode(child) : child);
<a name="line693"></a>    }
<a name="line694"></a>  }
<a name="line695"></a>
<a name="line696"></a>  for (var i = startIndex; i &lt; args.length; i++) {
<a name="line697"></a>    var arg = args[i];
<a name="line698"></a>    // TODO(attila): Fix isArrayLike to return false for a text node.
<a name="line699"></a>    if (goog.isArrayLike(arg) &amp;&amp; !goog.dom.isNodeLike(arg)) {
<a name="line700"></a>      // If the argument is a node list, not a real array, use a clone,
<a name="line701"></a>      // because forEach can&#39;t be used to mutate a NodeList.
<a name="line702"></a>      goog.array.forEach(goog.dom.isNodeList(arg) ?
<a name="line703"></a>          goog.array.toArray(arg) : arg,
<a name="line704"></a>          childHandler);
<a name="line705"></a>    } else {
<a name="line706"></a>      childHandler(arg);
<a name="line707"></a>    }
<a name="line708"></a>  }
<a name="line709"></a>};
<a name="line710"></a>
<a name="line711"></a>
<a name="line712"></a>/**
<a name="line713"></a> * Alias for {@code createDom}.
<a name="line714"></a> * @param {string} tagName Tag to create.
<a name="line715"></a> * @param {(string|Object)=} opt_attributes If object, then a map of name-value
<a name="line716"></a> *     pairs for attributes. If a string, then this is the className of the new
<a name="line717"></a> *     element.
<a name="line718"></a> * @param {...(Object|string|Array|NodeList)} var_args Further DOM nodes or
<a name="line719"></a> *     strings for text nodes. If one of the var_args is an array, its
<a name="line720"></a> *     children will be added as childNodes instead.
<a name="line721"></a> * @return {!Element} Reference to a DOM node.
<a name="line722"></a> * @deprecated Use {@link goog.dom.createDom} instead.
<a name="line723"></a> */
<a name="line724"></a>goog.dom.$dom = goog.dom.createDom;
<a name="line725"></a>
<a name="line726"></a>
<a name="line727"></a>/**
<a name="line728"></a> * Creates a new element.
<a name="line729"></a> * @param {string} name Tag name.
<a name="line730"></a> * @return {!Element} The new element.
<a name="line731"></a> */
<a name="line732"></a>goog.dom.createElement = function(name) {
<a name="line733"></a>  return document.createElement(name);
<a name="line734"></a>};
<a name="line735"></a>
<a name="line736"></a>
<a name="line737"></a>/**
<a name="line738"></a> * Creates a new text node.
<a name="line739"></a> * @param {number|string} content Content.
<a name="line740"></a> * @return {!Text} The new text node.
<a name="line741"></a> */
<a name="line742"></a>goog.dom.createTextNode = function(content) {
<a name="line743"></a>  return document.createTextNode(String(content));
<a name="line744"></a>};
<a name="line745"></a>
<a name="line746"></a>
<a name="line747"></a>/**
<a name="line748"></a> * Create a table.
<a name="line749"></a> * @param {number} rows The number of rows in the table.  Must be &gt;= 1.
<a name="line750"></a> * @param {number} columns The number of columns in the table.  Must be &gt;= 1.
<a name="line751"></a> * @param {boolean=} opt_fillWithNbsp If true, fills table entries with nsbps.
<a name="line752"></a> * @return {!Element} The created table.
<a name="line753"></a> */
<a name="line754"></a>goog.dom.createTable = function(rows, columns, opt_fillWithNbsp) {
<a name="line755"></a>  return goog.dom.createTable_(document, rows, columns, !!opt_fillWithNbsp);
<a name="line756"></a>};
<a name="line757"></a>
<a name="line758"></a>
<a name="line759"></a>/**
<a name="line760"></a> * Create a table.
<a name="line761"></a> * @param {!Document} doc Document object to use to create the table.
<a name="line762"></a> * @param {number} rows The number of rows in the table.  Must be &gt;= 1.
<a name="line763"></a> * @param {number} columns The number of columns in the table.  Must be &gt;= 1.
<a name="line764"></a> * @param {boolean} fillWithNbsp If true, fills table entries with nsbps.
<a name="line765"></a> * @return {!Element} The created table.
<a name="line766"></a> * @private
<a name="line767"></a> */
<a name="line768"></a>goog.dom.createTable_ = function(doc, rows, columns, fillWithNbsp) {
<a name="line769"></a>  var rowHtml = [&#39;&lt;tr&gt;&#39;];
<a name="line770"></a>  for (var i = 0; i &lt; columns; i++) {
<a name="line771"></a>    rowHtml.push(fillWithNbsp ? &#39;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&#39; : &#39;&lt;td&gt;&lt;/td&gt;&#39;);
<a name="line772"></a>  }
<a name="line773"></a>  rowHtml.push(&#39;&lt;/tr&gt;&#39;);
<a name="line774"></a>  rowHtml = rowHtml.join(&#39;&#39;);
<a name="line775"></a>  var totalHtml = [&#39;&lt;table&gt;&#39;];
<a name="line776"></a>  for (i = 0; i &lt; rows; i++) {
<a name="line777"></a>    totalHtml.push(rowHtml);
<a name="line778"></a>  }
<a name="line779"></a>  totalHtml.push(&#39;&lt;/table&gt;&#39;);
<a name="line780"></a>
<a name="line781"></a>  var elem = doc.createElement(goog.dom.TagName.DIV);
<a name="line782"></a>  elem.innerHTML = totalHtml.join(&#39;&#39;);
<a name="line783"></a>  return /** @type {!Element} */ (elem.removeChild(elem.firstChild));
<a name="line784"></a>};
<a name="line785"></a>
<a name="line786"></a>
<a name="line787"></a>/**
<a name="line788"></a> * Converts an HTML string into a document fragment. The string must be
<a name="line789"></a> * sanitized in order to avoid cross-site scripting. For example
<a name="line790"></a> * {@code goog.dom.htmlToDocumentFragment(&#39;&amp;lt;img src=x onerror=alert(0)&amp;gt;&#39;)}
<a name="line791"></a> * triggers an alert in all browsers, even if the returned document fragment
<a name="line792"></a> * is thrown away immediately.
<a name="line793"></a> *
<a name="line794"></a> * @param {string} htmlString The HTML string to convert.
<a name="line795"></a> * @return {!Node} The resulting document fragment.
<a name="line796"></a> */
<a name="line797"></a>goog.dom.htmlToDocumentFragment = function(htmlString) {
<a name="line798"></a>  return goog.dom.htmlToDocumentFragment_(document, htmlString);
<a name="line799"></a>};
<a name="line800"></a>
<a name="line801"></a>
<a name="line802"></a>/**
<a name="line803"></a> * Helper for {@code htmlToDocumentFragment}.
<a name="line804"></a> *
<a name="line805"></a> * @param {!Document} doc The document.
<a name="line806"></a> * @param {string} htmlString The HTML string to convert.
<a name="line807"></a> * @return {!Node} The resulting document fragment.
<a name="line808"></a> * @private
<a name="line809"></a> */
<a name="line810"></a>goog.dom.htmlToDocumentFragment_ = function(doc, htmlString) {
<a name="line811"></a>  var tempDiv = doc.createElement(&#39;div&#39;);
<a name="line812"></a>  if (goog.dom.BrowserFeature.INNER_HTML_NEEDS_SCOPED_ELEMENT) {
<a name="line813"></a>    tempDiv.innerHTML = &#39;&lt;br&gt;&#39; + htmlString;
<a name="line814"></a>    tempDiv.removeChild(tempDiv.firstChild);
<a name="line815"></a>  } else {
<a name="line816"></a>    tempDiv.innerHTML = htmlString;
<a name="line817"></a>  }
<a name="line818"></a>  if (tempDiv.childNodes.length == 1) {
<a name="line819"></a>    return /** @type {!Node} */ (tempDiv.removeChild(tempDiv.firstChild));
<a name="line820"></a>  } else {
<a name="line821"></a>    var fragment = doc.createDocumentFragment();
<a name="line822"></a>    while (tempDiv.firstChild) {
<a name="line823"></a>      fragment.appendChild(tempDiv.firstChild);
<a name="line824"></a>    }
<a name="line825"></a>    return fragment;
<a name="line826"></a>  }
<a name="line827"></a>};
<a name="line828"></a>
<a name="line829"></a>
<a name="line830"></a>/**
<a name="line831"></a> * Returns the compatMode of the document.
<a name="line832"></a> * @return {string} The result is either CSS1Compat or BackCompat.
<a name="line833"></a> * @deprecated use goog.dom.isCss1CompatMode instead.
<a name="line834"></a> */
<a name="line835"></a>goog.dom.getCompatMode = function() {
<a name="line836"></a>  return goog.dom.isCss1CompatMode() ? &#39;CSS1Compat&#39; : &#39;BackCompat&#39;;
<a name="line837"></a>};
<a name="line838"></a>
<a name="line839"></a>
<a name="line840"></a>/**
<a name="line841"></a> * Returns true if the browser is in &quot;CSS1-compatible&quot; (standards-compliant)
<a name="line842"></a> * mode, false otherwise.
<a name="line843"></a> * @return {boolean} True if in CSS1-compatible mode.
<a name="line844"></a> */
<a name="line845"></a>goog.dom.isCss1CompatMode = function() {
<a name="line846"></a>  return goog.dom.isCss1CompatMode_(document);
<a name="line847"></a>};
<a name="line848"></a>
<a name="line849"></a>
<a name="line850"></a>/**
<a name="line851"></a> * Returns true if the browser is in &quot;CSS1-compatible&quot; (standards-compliant)
<a name="line852"></a> * mode, false otherwise.
<a name="line853"></a> * @param {Document} doc The document to check.
<a name="line854"></a> * @return {boolean} True if in CSS1-compatible mode.
<a name="line855"></a> * @private
<a name="line856"></a> */
<a name="line857"></a>goog.dom.isCss1CompatMode_ = function(doc) {
<a name="line858"></a>  if (goog.dom.COMPAT_MODE_KNOWN_) {
<a name="line859"></a>    return goog.dom.ASSUME_STANDARDS_MODE;
<a name="line860"></a>  }
<a name="line861"></a>
<a name="line862"></a>  return doc.compatMode == &#39;CSS1Compat&#39;;
<a name="line863"></a>};
<a name="line864"></a>
<a name="line865"></a>
<a name="line866"></a>/**
<a name="line867"></a> * Determines if the given node can contain children, intended to be used for
<a name="line868"></a> * HTML generation.
<a name="line869"></a> *
<a name="line870"></a> * IE natively supports node.canHaveChildren but has inconsistent behavior.
<a name="line871"></a> * Prior to IE8 the base tag allows children and in IE9 all nodes return true
<a name="line872"></a> * for canHaveChildren.
<a name="line873"></a> *
<a name="line874"></a> * In practice all non-IE browsers allow you to add children to any node, but
<a name="line875"></a> * the behavior is inconsistent:
<a name="line876"></a> *
<a name="line877"></a> * &lt;pre&gt;
<a name="line878"></a> *   var a = document.createElement(&#39;br&#39;);
<a name="line879"></a> *   a.appendChild(document.createTextNode(&#39;foo&#39;));
<a name="line880"></a> *   a.appendChild(document.createTextNode(&#39;bar&#39;));
<a name="line881"></a> *   console.log(a.childNodes.length);  // 2
<a name="line882"></a> *   console.log(a.innerHTML);  // Chrome: &quot;&quot;, IE9: &quot;foobar&quot;, FF3.5: &quot;foobar&quot;
<a name="line883"></a> * &lt;/pre&gt;
<a name="line884"></a> *
<a name="line885"></a> * For more information, see:
<a name="line886"></a> * http://dev.w3.org/html5/markup/syntax.html#syntax-elements
<a name="line887"></a> *
<a name="line888"></a> * TODO(user): Rename shouldAllowChildren() ?
<a name="line889"></a> *
<a name="line890"></a> * @param {Node} node The node to check.
<a name="line891"></a> * @return {boolean} Whether the node can contain children.
<a name="line892"></a> */
<a name="line893"></a>goog.dom.canHaveChildren = function(node) {
<a name="line894"></a>  if (node.nodeType != goog.dom.NodeType.ELEMENT) {
<a name="line895"></a>    return false;
<a name="line896"></a>  }
<a name="line897"></a>  switch (node.tagName) {
<a name="line898"></a>    case goog.dom.TagName.APPLET:
<a name="line899"></a>    case goog.dom.TagName.AREA:
<a name="line900"></a>    case goog.dom.TagName.BASE:
<a name="line901"></a>    case goog.dom.TagName.BR:
<a name="line902"></a>    case goog.dom.TagName.COL:
<a name="line903"></a>    case goog.dom.TagName.COMMAND:
<a name="line904"></a>    case goog.dom.TagName.EMBED:
<a name="line905"></a>    case goog.dom.TagName.FRAME:
<a name="line906"></a>    case goog.dom.TagName.HR:
<a name="line907"></a>    case goog.dom.TagName.IMG:
<a name="line908"></a>    case goog.dom.TagName.INPUT:
<a name="line909"></a>    case goog.dom.TagName.IFRAME:
<a name="line910"></a>    case goog.dom.TagName.ISINDEX:
<a name="line911"></a>    case goog.dom.TagName.KEYGEN:
<a name="line912"></a>    case goog.dom.TagName.LINK:
<a name="line913"></a>    case goog.dom.TagName.NOFRAMES:
<a name="line914"></a>    case goog.dom.TagName.NOSCRIPT:
<a name="line915"></a>    case goog.dom.TagName.META:
<a name="line916"></a>    case goog.dom.TagName.OBJECT:
<a name="line917"></a>    case goog.dom.TagName.PARAM:
<a name="line918"></a>    case goog.dom.TagName.SCRIPT:
<a name="line919"></a>    case goog.dom.TagName.SOURCE:
<a name="line920"></a>    case goog.dom.TagName.STYLE:
<a name="line921"></a>    case goog.dom.TagName.TRACK:
<a name="line922"></a>    case goog.dom.TagName.WBR:
<a name="line923"></a>      return false;
<a name="line924"></a>  }
<a name="line925"></a>  return true;
<a name="line926"></a>};
<a name="line927"></a>
<a name="line928"></a>
<a name="line929"></a>/**
<a name="line930"></a> * Appends a child to a node.
<a name="line931"></a> * @param {Node} parent Parent.
<a name="line932"></a> * @param {Node} child Child.
<a name="line933"></a> */
<a name="line934"></a>goog.dom.appendChild = function(parent, child) {
<a name="line935"></a>  parent.appendChild(child);
<a name="line936"></a>};
<a name="line937"></a>
<a name="line938"></a>
<a name="line939"></a>/**
<a name="line940"></a> * Appends a node with text or other nodes.
<a name="line941"></a> * @param {!Node} parent The node to append nodes to.
<a name="line942"></a> * @param {...goog.dom.Appendable} var_args The things to append to the node.
<a name="line943"></a> *     If this is a Node it is appended as is.
<a name="line944"></a> *     If this is a string then a text node is appended.
<a name="line945"></a> *     If this is an array like object then fields 0 to length - 1 are appended.
<a name="line946"></a> */
<a name="line947"></a>goog.dom.append = function(parent, var_args) {
<a name="line948"></a>  goog.dom.append_(goog.dom.getOwnerDocument(parent), parent, arguments, 1);
<a name="line949"></a>};
<a name="line950"></a>
<a name="line951"></a>
<a name="line952"></a>/**
<a name="line953"></a> * Removes all the child nodes on a DOM node.
<a name="line954"></a> * @param {Node} node Node to remove children from.
<a name="line955"></a> */
<a name="line956"></a>goog.dom.removeChildren = function(node) {
<a name="line957"></a>  // Note: Iterations over live collections can be slow, this is the fastest
<a name="line958"></a>  // we could find. The double parenthesis are used to prevent JsCompiler and
<a name="line959"></a>  // strict warnings.
<a name="line960"></a>  var child;
<a name="line961"></a>  while ((child = node.firstChild)) {
<a name="line962"></a>    node.removeChild(child);
<a name="line963"></a>  }
<a name="line964"></a>};
<a name="line965"></a>
<a name="line966"></a>
<a name="line967"></a>/**
<a name="line968"></a> * Inserts a new node before an existing reference node (i.e. as the previous
<a name="line969"></a> * sibling). If the reference node has no parent, then does nothing.
<a name="line970"></a> * @param {Node} newNode Node to insert.
<a name="line971"></a> * @param {Node} refNode Reference node to insert before.
<a name="line972"></a> */
<a name="line973"></a>goog.dom.insertSiblingBefore = function(newNode, refNode) {
<a name="line974"></a>  if (refNode.parentNode) {
<a name="line975"></a>    refNode.parentNode.insertBefore(newNode, refNode);
<a name="line976"></a>  }
<a name="line977"></a>};
<a name="line978"></a>
<a name="line979"></a>
<a name="line980"></a>/**
<a name="line981"></a> * Inserts a new node after an existing reference node (i.e. as the next
<a name="line982"></a> * sibling). If the reference node has no parent, then does nothing.
<a name="line983"></a> * @param {Node} newNode Node to insert.
<a name="line984"></a> * @param {Node} refNode Reference node to insert after.
<a name="line985"></a> */
<a name="line986"></a>goog.dom.insertSiblingAfter = function(newNode, refNode) {
<a name="line987"></a>  if (refNode.parentNode) {
<a name="line988"></a>    refNode.parentNode.insertBefore(newNode, refNode.nextSibling);
<a name="line989"></a>  }
<a name="line990"></a>};
<a name="line991"></a>
<a name="line992"></a>
<a name="line993"></a>/**
<a name="line994"></a> * Insert a child at a given index. If index is larger than the number of child
<a name="line995"></a> * nodes that the parent currently has, the node is inserted as the last child
<a name="line996"></a> * node.
<a name="line997"></a> * @param {Element} parent The element into which to insert the child.
<a name="line998"></a> * @param {Node} child The element to insert.
<a name="line999"></a> * @param {number} index The index at which to insert the new child node. Must
<a name="line1000"></a> *     not be negative.
<a name="line1001"></a> */
<a name="line1002"></a>goog.dom.insertChildAt = function(parent, child, index) {
<a name="line1003"></a>  // Note that if the second argument is null, insertBefore
<a name="line1004"></a>  // will append the child at the end of the list of children.
<a name="line1005"></a>  parent.insertBefore(child, parent.childNodes[index] || null);
<a name="line1006"></a>};
<a name="line1007"></a>
<a name="line1008"></a>
<a name="line1009"></a>/**
<a name="line1010"></a> * Removes a node from its parent.
<a name="line1011"></a> * @param {Node} node The node to remove.
<a name="line1012"></a> * @return {Node} The node removed if removed; else, null.
<a name="line1013"></a> */
<a name="line1014"></a>goog.dom.removeNode = function(node) {
<a name="line1015"></a>  return node &amp;&amp; node.parentNode ? node.parentNode.removeChild(node) : null;
<a name="line1016"></a>};
<a name="line1017"></a>
<a name="line1018"></a>
<a name="line1019"></a>/**
<a name="line1020"></a> * Replaces a node in the DOM tree. Will do nothing if {@code oldNode} has no
<a name="line1021"></a> * parent.
<a name="line1022"></a> * @param {Node} newNode Node to insert.
<a name="line1023"></a> * @param {Node} oldNode Node to replace.
<a name="line1024"></a> */
<a name="line1025"></a>goog.dom.replaceNode = function(newNode, oldNode) {
<a name="line1026"></a>  var parent = oldNode.parentNode;
<a name="line1027"></a>  if (parent) {
<a name="line1028"></a>    parent.replaceChild(newNode, oldNode);
<a name="line1029"></a>  }
<a name="line1030"></a>};
<a name="line1031"></a>
<a name="line1032"></a>
<a name="line1033"></a>/**
<a name="line1034"></a> * Flattens an element. That is, removes it and replace it with its children.
<a name="line1035"></a> * Does nothing if the element is not in the document.
<a name="line1036"></a> * @param {Element} element The element to flatten.
<a name="line1037"></a> * @return {Element|undefined} The original element, detached from the document
<a name="line1038"></a> *     tree, sans children; or undefined, if the element was not in the document
<a name="line1039"></a> *     to begin with.
<a name="line1040"></a> */
<a name="line1041"></a>goog.dom.flattenElement = function(element) {
<a name="line1042"></a>  var child, parent = element.parentNode;
<a name="line1043"></a>  if (parent &amp;&amp; parent.nodeType != goog.dom.NodeType.DOCUMENT_FRAGMENT) {
<a name="line1044"></a>    // Use IE DOM method (supported by Opera too) if available
<a name="line1045"></a>    if (element.removeNode) {
<a name="line1046"></a>      return /** @type {Element} */ (element.removeNode(false));
<a name="line1047"></a>    } else {
<a name="line1048"></a>      // Move all children of the original node up one level.
<a name="line1049"></a>      while ((child = element.firstChild)) {
<a name="line1050"></a>        parent.insertBefore(child, element);
<a name="line1051"></a>      }
<a name="line1052"></a>
<a name="line1053"></a>      // Detach the original element.
<a name="line1054"></a>      return /** @type {Element} */ (goog.dom.removeNode(element));
<a name="line1055"></a>    }
<a name="line1056"></a>  }
<a name="line1057"></a>};
<a name="line1058"></a>
<a name="line1059"></a>
<a name="line1060"></a>/**
<a name="line1061"></a> * Returns an array containing just the element children of the given element.
<a name="line1062"></a> * @param {Element} element The element whose element children we want.
<a name="line1063"></a> * @return {!(Array|NodeList)} An array or array-like list of just the element
<a name="line1064"></a> *     children of the given element.
<a name="line1065"></a> */
<a name="line1066"></a>goog.dom.getChildren = function(element) {
<a name="line1067"></a>  // We check if the children attribute is supported for child elements
<a name="line1068"></a>  // since IE8 misuses the attribute by also including comments.
<a name="line1069"></a>  if (goog.dom.BrowserFeature.CAN_USE_CHILDREN_ATTRIBUTE &amp;&amp;
<a name="line1070"></a>      element.children != undefined) {
<a name="line1071"></a>    return element.children;
<a name="line1072"></a>  }
<a name="line1073"></a>  // Fall back to manually filtering the element&#39;s child nodes.
<a name="line1074"></a>  return goog.array.filter(element.childNodes, function(node) {
<a name="line1075"></a>    return node.nodeType == goog.dom.NodeType.ELEMENT;
<a name="line1076"></a>  });
<a name="line1077"></a>};
<a name="line1078"></a>
<a name="line1079"></a>
<a name="line1080"></a>/**
<a name="line1081"></a> * Returns the first child node that is an element.
<a name="line1082"></a> * @param {Node} node The node to get the first child element of.
<a name="line1083"></a> * @return {Element} The first child node of {@code node} that is an element.
<a name="line1084"></a> */
<a name="line1085"></a>goog.dom.getFirstElementChild = function(node) {
<a name="line1086"></a>  if (node.firstElementChild != undefined) {
<a name="line1087"></a>    return /** @type {Element} */(node).firstElementChild;
<a name="line1088"></a>  }
<a name="line1089"></a>  return goog.dom.getNextElementNode_(node.firstChild, true);
<a name="line1090"></a>};
<a name="line1091"></a>
<a name="line1092"></a>
<a name="line1093"></a>/**
<a name="line1094"></a> * Returns the last child node that is an element.
<a name="line1095"></a> * @param {Node} node The node to get the last child element of.
<a name="line1096"></a> * @return {Element} The last child node of {@code node} that is an element.
<a name="line1097"></a> */
<a name="line1098"></a>goog.dom.getLastElementChild = function(node) {
<a name="line1099"></a>  if (node.lastElementChild != undefined) {
<a name="line1100"></a>    return /** @type {Element} */(node).lastElementChild;
<a name="line1101"></a>  }
<a name="line1102"></a>  return goog.dom.getNextElementNode_(node.lastChild, false);
<a name="line1103"></a>};
<a name="line1104"></a>
<a name="line1105"></a>
<a name="line1106"></a>/**
<a name="line1107"></a> * Returns the first next sibling that is an element.
<a name="line1108"></a> * @param {Node} node The node to get the next sibling element of.
<a name="line1109"></a> * @return {Element} The next sibling of {@code node} that is an element.
<a name="line1110"></a> */
<a name="line1111"></a>goog.dom.getNextElementSibling = function(node) {
<a name="line1112"></a>  if (node.nextElementSibling != undefined) {
<a name="line1113"></a>    return /** @type {Element} */(node).nextElementSibling;
<a name="line1114"></a>  }
<a name="line1115"></a>  return goog.dom.getNextElementNode_(node.nextSibling, true);
<a name="line1116"></a>};
<a name="line1117"></a>
<a name="line1118"></a>
<a name="line1119"></a>/**
<a name="line1120"></a> * Returns the first previous sibling that is an element.
<a name="line1121"></a> * @param {Node} node The node to get the previous sibling element of.
<a name="line1122"></a> * @return {Element} The first previous sibling of {@code node} that is
<a name="line1123"></a> *     an element.
<a name="line1124"></a> */
<a name="line1125"></a>goog.dom.getPreviousElementSibling = function(node) {
<a name="line1126"></a>  if (node.previousElementSibling != undefined) {
<a name="line1127"></a>    return /** @type {Element} */(node).previousElementSibling;
<a name="line1128"></a>  }
<a name="line1129"></a>  return goog.dom.getNextElementNode_(node.previousSibling, false);
<a name="line1130"></a>};
<a name="line1131"></a>
<a name="line1132"></a>
<a name="line1133"></a>/**
<a name="line1134"></a> * Returns the first node that is an element in the specified direction,
<a name="line1135"></a> * starting with {@code node}.
<a name="line1136"></a> * @param {Node} node The node to get the next element from.
<a name="line1137"></a> * @param {boolean} forward Whether to look forwards or backwards.
<a name="line1138"></a> * @return {Element} The first element.
<a name="line1139"></a> * @private
<a name="line1140"></a> */
<a name="line1141"></a>goog.dom.getNextElementNode_ = function(node, forward) {
<a name="line1142"></a>  while (node &amp;&amp; node.nodeType != goog.dom.NodeType.ELEMENT) {
<a name="line1143"></a>    node = forward ? node.nextSibling : node.previousSibling;
<a name="line1144"></a>  }
<a name="line1145"></a>
<a name="line1146"></a>  return /** @type {Element} */ (node);
<a name="line1147"></a>};
<a name="line1148"></a>
<a name="line1149"></a>
<a name="line1150"></a>/**
<a name="line1151"></a> * Returns the next node in source order from the given node.
<a name="line1152"></a> * @param {Node} node The node.
<a name="line1153"></a> * @return {Node} The next node in the DOM tree, or null if this was the last
<a name="line1154"></a> *     node.
<a name="line1155"></a> */
<a name="line1156"></a>goog.dom.getNextNode = function(node) {
<a name="line1157"></a>  if (!node) {
<a name="line1158"></a>    return null;
<a name="line1159"></a>  }
<a name="line1160"></a>
<a name="line1161"></a>  if (node.firstChild) {
<a name="line1162"></a>    return node.firstChild;
<a name="line1163"></a>  }
<a name="line1164"></a>
<a name="line1165"></a>  while (node &amp;&amp; !node.nextSibling) {
<a name="line1166"></a>    node = node.parentNode;
<a name="line1167"></a>  }
<a name="line1168"></a>
<a name="line1169"></a>  return node ? node.nextSibling : null;
<a name="line1170"></a>};
<a name="line1171"></a>
<a name="line1172"></a>
<a name="line1173"></a>/**
<a name="line1174"></a> * Returns the previous node in source order from the given node.
<a name="line1175"></a> * @param {Node} node The node.
<a name="line1176"></a> * @return {Node} The previous node in the DOM tree, or null if this was the
<a name="line1177"></a> *     first node.
<a name="line1178"></a> */
<a name="line1179"></a>goog.dom.getPreviousNode = function(node) {
<a name="line1180"></a>  if (!node) {
<a name="line1181"></a>    return null;
<a name="line1182"></a>  }
<a name="line1183"></a>
<a name="line1184"></a>  if (!node.previousSibling) {
<a name="line1185"></a>    return node.parentNode;
<a name="line1186"></a>  }
<a name="line1187"></a>
<a name="line1188"></a>  node = node.previousSibling;
<a name="line1189"></a>  while (node &amp;&amp; node.lastChild) {
<a name="line1190"></a>    node = node.lastChild;
<a name="line1191"></a>  }
<a name="line1192"></a>
<a name="line1193"></a>  return node;
<a name="line1194"></a>};
<a name="line1195"></a>
<a name="line1196"></a>
<a name="line1197"></a>/**
<a name="line1198"></a> * Whether the object looks like a DOM node.
<a name="line1199"></a> * @param {*} obj The object being tested for node likeness.
<a name="line1200"></a> * @return {boolean} Whether the object looks like a DOM node.
<a name="line1201"></a> */
<a name="line1202"></a>goog.dom.isNodeLike = function(obj) {
<a name="line1203"></a>  return goog.isObject(obj) &amp;&amp; obj.nodeType &gt; 0;
<a name="line1204"></a>};
<a name="line1205"></a>
<a name="line1206"></a>
<a name="line1207"></a>/**
<a name="line1208"></a> * Whether the object looks like an Element.
<a name="line1209"></a> * @param {*} obj The object being tested for Element likeness.
<a name="line1210"></a> * @return {boolean} Whether the object looks like an Element.
<a name="line1211"></a> */
<a name="line1212"></a>goog.dom.isElement = function(obj) {
<a name="line1213"></a>  return goog.isObject(obj) &amp;&amp; obj.nodeType == goog.dom.NodeType.ELEMENT;
<a name="line1214"></a>};
<a name="line1215"></a>
<a name="line1216"></a>
<a name="line1217"></a>/**
<a name="line1218"></a> * Returns true if the specified value is a Window object. This includes the
<a name="line1219"></a> * global window for HTML pages, and iframe windows.
<a name="line1220"></a> * @param {*} obj Variable to test.
<a name="line1221"></a> * @return {boolean} Whether the variable is a window.
<a name="line1222"></a> */
<a name="line1223"></a>goog.dom.isWindow = function(obj) {
<a name="line1224"></a>  return goog.isObject(obj) &amp;&amp; obj[&#39;window&#39;] == obj;
<a name="line1225"></a>};
<a name="line1226"></a>
<a name="line1227"></a>
<a name="line1228"></a>/**
<a name="line1229"></a> * Returns an element&#39;s parent, if it&#39;s an Element.
<a name="line1230"></a> * @param {Element} element The DOM element.
<a name="line1231"></a> * @return {Element} The parent, or null if not an Element.
<a name="line1232"></a> */
<a name="line1233"></a>goog.dom.getParentElement = function(element) {
<a name="line1234"></a>  if (goog.dom.BrowserFeature.CAN_USE_PARENT_ELEMENT_PROPERTY) {
<a name="line1235"></a>    return element.parentElement;
<a name="line1236"></a>  }
<a name="line1237"></a>  var parent = element.parentNode;
<a name="line1238"></a>  return goog.dom.isElement(parent) ? /** @type {!Element} */ (parent) : null;
<a name="line1239"></a>};
<a name="line1240"></a>
<a name="line1241"></a>
<a name="line1242"></a>/**
<a name="line1243"></a> * Whether a node contains another node.
<a name="line1244"></a> * @param {Node} parent The node that should contain the other node.
<a name="line1245"></a> * @param {Node} descendant The node to test presence of.
<a name="line1246"></a> * @return {boolean} Whether the parent node contains the descendent node.
<a name="line1247"></a> */
<a name="line1248"></a>goog.dom.contains = function(parent, descendant) {
<a name="line1249"></a>  // We use browser specific methods for this if available since it is faster
<a name="line1250"></a>  // that way.
<a name="line1251"></a>
<a name="line1252"></a>  // IE DOM
<a name="line1253"></a>  if (parent.contains &amp;&amp; descendant.nodeType == goog.dom.NodeType.ELEMENT) {
<a name="line1254"></a>    return parent == descendant || parent.contains(descendant);
<a name="line1255"></a>  }
<a name="line1256"></a>
<a name="line1257"></a>  // W3C DOM Level 3
<a name="line1258"></a>  if (typeof parent.compareDocumentPosition != &#39;undefined&#39;) {
<a name="line1259"></a>    return parent == descendant ||
<a name="line1260"></a>        Boolean(parent.compareDocumentPosition(descendant) &amp; 16);
<a name="line1261"></a>  }
<a name="line1262"></a>
<a name="line1263"></a>  // W3C DOM Level 1
<a name="line1264"></a>  while (descendant &amp;&amp; parent != descendant) {
<a name="line1265"></a>    descendant = descendant.parentNode;
<a name="line1266"></a>  }
<a name="line1267"></a>  return descendant == parent;
<a name="line1268"></a>};
<a name="line1269"></a>
<a name="line1270"></a>
<a name="line1271"></a>/**
<a name="line1272"></a> * Compares the document order of two nodes, returning 0 if they are the same
<a name="line1273"></a> * node, a negative number if node1 is before node2, and a positive number if
<a name="line1274"></a> * node2 is before node1.  Note that we compare the order the tags appear in the
<a name="line1275"></a> * document so in the tree &lt;b&gt;&lt;i&gt;text&lt;/i&gt;&lt;/b&gt; the B node is considered to be
<a name="line1276"></a> * before the I node.
<a name="line1277"></a> *
<a name="line1278"></a> * @param {Node} node1 The first node to compare.
<a name="line1279"></a> * @param {Node} node2 The second node to compare.
<a name="line1280"></a> * @return {number} 0 if the nodes are the same node, a negative number if node1
<a name="line1281"></a> *     is before node2, and a positive number if node2 is before node1.
<a name="line1282"></a> */
<a name="line1283"></a>goog.dom.compareNodeOrder = function(node1, node2) {
<a name="line1284"></a>  // Fall out quickly for equality.
<a name="line1285"></a>  if (node1 == node2) {
<a name="line1286"></a>    return 0;
<a name="line1287"></a>  }
<a name="line1288"></a>
<a name="line1289"></a>  // Use compareDocumentPosition where available
<a name="line1290"></a>  if (node1.compareDocumentPosition) {
<a name="line1291"></a>    // 4 is the bitmask for FOLLOWS.
<a name="line1292"></a>    return node1.compareDocumentPosition(node2) &amp; 2 ? 1 : -1;
<a name="line1293"></a>  }
<a name="line1294"></a>
<a name="line1295"></a>  // Special case for document nodes on IE 7 and 8.
<a name="line1296"></a>  if (goog.userAgent.IE &amp;&amp; !goog.userAgent.isDocumentMode(9)) {
<a name="line1297"></a>    if (node1.nodeType == goog.dom.NodeType.DOCUMENT) {
<a name="line1298"></a>      return -1;
<a name="line1299"></a>    }
<a name="line1300"></a>    if (node2.nodeType == goog.dom.NodeType.DOCUMENT) {
<a name="line1301"></a>      return 1;
<a name="line1302"></a>    }
<a name="line1303"></a>  }
<a name="line1304"></a>
<a name="line1305"></a>  // Process in IE using sourceIndex - we check to see if the first node has
<a name="line1306"></a>  // a source index or if its parent has one.
<a name="line1307"></a>  if (&#39;sourceIndex&#39; in node1 ||
<a name="line1308"></a>      (node1.parentNode &amp;&amp; &#39;sourceIndex&#39; in node1.parentNode)) {
<a name="line1309"></a>    var isElement1 = node1.nodeType == goog.dom.NodeType.ELEMENT;
<a name="line1310"></a>    var isElement2 = node2.nodeType == goog.dom.NodeType.ELEMENT;
<a name="line1311"></a>
<a name="line1312"></a>    if (isElement1 &amp;&amp; isElement2) {
<a name="line1313"></a>      return node1.sourceIndex - node2.sourceIndex;
<a name="line1314"></a>    } else {
<a name="line1315"></a>      var parent1 = node1.parentNode;
<a name="line1316"></a>      var parent2 = node2.parentNode;
<a name="line1317"></a>
<a name="line1318"></a>      if (parent1 == parent2) {
<a name="line1319"></a>        return goog.dom.compareSiblingOrder_(node1, node2);
<a name="line1320"></a>      }
<a name="line1321"></a>
<a name="line1322"></a>      if (!isElement1 &amp;&amp; goog.dom.contains(parent1, node2)) {
<a name="line1323"></a>        return -1 * goog.dom.compareParentsDescendantNodeIe_(node1, node2);
<a name="line1324"></a>      }
<a name="line1325"></a>
<a name="line1326"></a>
<a name="line1327"></a>      if (!isElement2 &amp;&amp; goog.dom.contains(parent2, node1)) {
<a name="line1328"></a>        return goog.dom.compareParentsDescendantNodeIe_(node2, node1);
<a name="line1329"></a>      }
<a name="line1330"></a>
<a name="line1331"></a>      return (isElement1 ? node1.sourceIndex : parent1.sourceIndex) -
<a name="line1332"></a>             (isElement2 ? node2.sourceIndex : parent2.sourceIndex);
<a name="line1333"></a>    }
<a name="line1334"></a>  }
<a name="line1335"></a>
<a name="line1336"></a>  // For Safari, we compare ranges.
<a name="line1337"></a>  var doc = goog.dom.getOwnerDocument(node1);
<a name="line1338"></a>
<a name="line1339"></a>  var range1, range2;
<a name="line1340"></a>  range1 = doc.createRange();
<a name="line1341"></a>  range1.selectNode(node1);
<a name="line1342"></a>  range1.collapse(true);
<a name="line1343"></a>
<a name="line1344"></a>  range2 = doc.createRange();
<a name="line1345"></a>  range2.selectNode(node2);
<a name="line1346"></a>  range2.collapse(true);
<a name="line1347"></a>
<a name="line1348"></a>  return range1.compareBoundaryPoints(goog.global[&#39;Range&#39;].START_TO_END,
<a name="line1349"></a>      range2);
<a name="line1350"></a>};
<a name="line1351"></a>
<a name="line1352"></a>
<a name="line1353"></a>/**
<a name="line1354"></a> * Utility function to compare the position of two nodes, when
<a name="line1355"></a> * {@code textNode}&#39;s parent is an ancestor of {@code node}.  If this entry
<a name="line1356"></a> * condition is not met, this function will attempt to reference a null object.
<a name="line1357"></a> * @param {Node} textNode The textNode to compare.
<a name="line1358"></a> * @param {Node} node The node to compare.
<a name="line1359"></a> * @return {number} -1 if node is before textNode, +1 otherwise.
<a name="line1360"></a> * @private
<a name="line1361"></a> */
<a name="line1362"></a>goog.dom.compareParentsDescendantNodeIe_ = function(textNode, node) {
<a name="line1363"></a>  var parent = textNode.parentNode;
<a name="line1364"></a>  if (parent == node) {
<a name="line1365"></a>    // If textNode is a child of node, then node comes first.
<a name="line1366"></a>    return -1;
<a name="line1367"></a>  }
<a name="line1368"></a>  var sibling = node;
<a name="line1369"></a>  while (sibling.parentNode != parent) {
<a name="line1370"></a>    sibling = sibling.parentNode;
<a name="line1371"></a>  }
<a name="line1372"></a>  return goog.dom.compareSiblingOrder_(sibling, textNode);
<a name="line1373"></a>};
<a name="line1374"></a>
<a name="line1375"></a>
<a name="line1376"></a>/**
<a name="line1377"></a> * Utility function to compare the position of two nodes known to be non-equal
<a name="line1378"></a> * siblings.
<a name="line1379"></a> * @param {Node} node1 The first node to compare.
<a name="line1380"></a> * @param {Node} node2 The second node to compare.
<a name="line1381"></a> * @return {number} -1 if node1 is before node2, +1 otherwise.
<a name="line1382"></a> * @private
<a name="line1383"></a> */
<a name="line1384"></a>goog.dom.compareSiblingOrder_ = function(node1, node2) {
<a name="line1385"></a>  var s = node2;
<a name="line1386"></a>  while ((s = s.previousSibling)) {
<a name="line1387"></a>    if (s == node1) {
<a name="line1388"></a>      // We just found node1 before node2.
<a name="line1389"></a>      return -1;
<a name="line1390"></a>    }
<a name="line1391"></a>  }
<a name="line1392"></a>
<a name="line1393"></a>  // Since we didn&#39;t find it, node1 must be after node2.
<a name="line1394"></a>  return 1;
<a name="line1395"></a>};
<a name="line1396"></a>
<a name="line1397"></a>
<a name="line1398"></a>/**
<a name="line1399"></a> * Find the deepest common ancestor of the given nodes.
<a name="line1400"></a> * @param {...Node} var_args The nodes to find a common ancestor of.
<a name="line1401"></a> * @return {Node} The common ancestor of the nodes, or null if there is none.
<a name="line1402"></a> *     null will only be returned if two or more of the nodes are from different
<a name="line1403"></a> *     documents.
<a name="line1404"></a> */
<a name="line1405"></a>goog.dom.findCommonAncestor = function(var_args) {
<a name="line1406"></a>  var i, count = arguments.length;
<a name="line1407"></a>  if (!count) {
<a name="line1408"></a>    return null;
<a name="line1409"></a>  } else if (count == 1) {
<a name="line1410"></a>    return arguments[0];
<a name="line1411"></a>  }
<a name="line1412"></a>
<a name="line1413"></a>  var paths = [];
<a name="line1414"></a>  var minLength = Infinity;
<a name="line1415"></a>  for (i = 0; i &lt; count; i++) {
<a name="line1416"></a>    // Compute the list of ancestors.
<a name="line1417"></a>    var ancestors = [];
<a name="line1418"></a>    var node = arguments[i];
<a name="line1419"></a>    while (node) {
<a name="line1420"></a>      ancestors.unshift(node);
<a name="line1421"></a>      node = node.parentNode;
<a name="line1422"></a>    }
<a name="line1423"></a>
<a name="line1424"></a>    // Save the list for comparison.
<a name="line1425"></a>    paths.push(ancestors);
<a name="line1426"></a>    minLength = Math.min(minLength, ancestors.length);
<a name="line1427"></a>  }
<a name="line1428"></a>  var output = null;
<a name="line1429"></a>  for (i = 0; i &lt; minLength; i++) {
<a name="line1430"></a>    var first = paths[0][i];
<a name="line1431"></a>    for (var j = 1; j &lt; count; j++) {
<a name="line1432"></a>      if (first != paths[j][i]) {
<a name="line1433"></a>        return output;
<a name="line1434"></a>      }
<a name="line1435"></a>    }
<a name="line1436"></a>    output = first;
<a name="line1437"></a>  }
<a name="line1438"></a>  return output;
<a name="line1439"></a>};
<a name="line1440"></a>
<a name="line1441"></a>
<a name="line1442"></a>/**
<a name="line1443"></a> * Returns the owner document for a node.
<a name="line1444"></a> * @param {Node|Window} node The node to get the document for.
<a name="line1445"></a> * @return {!Document} The document owning the node.
<a name="line1446"></a> */
<a name="line1447"></a>goog.dom.getOwnerDocument = function(node) {
<a name="line1448"></a>  // TODO(arv): Remove IE5 code.
<a name="line1449"></a>  // IE5 uses document instead of ownerDocument
<a name="line1450"></a>  return /** @type {!Document} */ (
<a name="line1451"></a>      node.nodeType == goog.dom.NodeType.DOCUMENT ? node :
<a name="line1452"></a>      node.ownerDocument || node.document);
<a name="line1453"></a>};
<a name="line1454"></a>
<a name="line1455"></a>
<a name="line1456"></a>/**
<a name="line1457"></a> * Cross-browser function for getting the document element of a frame or iframe.
<a name="line1458"></a> * @param {Element} frame Frame element.
<a name="line1459"></a> * @return {!Document} The frame content document.
<a name="line1460"></a> */
<a name="line1461"></a>goog.dom.getFrameContentDocument = function(frame) {
<a name="line1462"></a>  var doc = frame.contentDocument || frame.contentWindow.document;
<a name="line1463"></a>  return doc;
<a name="line1464"></a>};
<a name="line1465"></a>
<a name="line1466"></a>
<a name="line1467"></a>/**
<a name="line1468"></a> * Cross-browser function for getting the window of a frame or iframe.
<a name="line1469"></a> * @param {Element} frame Frame element.
<a name="line1470"></a> * @return {Window} The window associated with the given frame.
<a name="line1471"></a> */
<a name="line1472"></a>goog.dom.getFrameContentWindow = function(frame) {
<a name="line1473"></a>  return frame.contentWindow ||
<a name="line1474"></a>      goog.dom.getWindow_(goog.dom.getFrameContentDocument(frame));
<a name="line1475"></a>};
<a name="line1476"></a>
<a name="line1477"></a>
<a name="line1478"></a>/**
<a name="line1479"></a> * Cross-browser function for setting the text content of an element.
<a name="line1480"></a> * @param {Element} element The element to change the text content of.
<a name="line1481"></a> * @param {string|number} text The string that should replace the current
<a name="line1482"></a> *     element content.
<a name="line1483"></a> */
<a name="line1484"></a>goog.dom.setTextContent = function(element, text) {
<a name="line1485"></a>  if (&#39;textContent&#39; in element) {
<a name="line1486"></a>    element.textContent = text;
<a name="line1487"></a>  } else if (element.firstChild &amp;&amp;
<a name="line1488"></a>             element.firstChild.nodeType == goog.dom.NodeType.TEXT) {
<a name="line1489"></a>    // If the first child is a text node we just change its data and remove the
<a name="line1490"></a>    // rest of the children.
<a name="line1491"></a>    while (element.lastChild != element.firstChild) {
<a name="line1492"></a>      element.removeChild(element.lastChild);
<a name="line1493"></a>    }
<a name="line1494"></a>    element.firstChild.data = text;
<a name="line1495"></a>  } else {
<a name="line1496"></a>    goog.dom.removeChildren(element);
<a name="line1497"></a>    var doc = goog.dom.getOwnerDocument(element);
<a name="line1498"></a>    element.appendChild(doc.createTextNode(String(text)));
<a name="line1499"></a>  }
<a name="line1500"></a>};
<a name="line1501"></a>
<a name="line1502"></a>
<a name="line1503"></a>/**
<a name="line1504"></a> * Gets the outerHTML of a node, which islike innerHTML, except that it
<a name="line1505"></a> * actually contains the HTML of the node itself.
<a name="line1506"></a> * @param {Element} element The element to get the HTML of.
<a name="line1507"></a> * @return {string} The outerHTML of the given element.
<a name="line1508"></a> */
<a name="line1509"></a>goog.dom.getOuterHtml = function(element) {
<a name="line1510"></a>  // IE, Opera and WebKit all have outerHTML.
<a name="line1511"></a>  if (&#39;outerHTML&#39; in element) {
<a name="line1512"></a>    return element.outerHTML;
<a name="line1513"></a>  } else {
<a name="line1514"></a>    var doc = goog.dom.getOwnerDocument(element);
<a name="line1515"></a>    var div = doc.createElement(&#39;div&#39;);
<a name="line1516"></a>    div.appendChild(element.cloneNode(true));
<a name="line1517"></a>    return div.innerHTML;
<a name="line1518"></a>  }
<a name="line1519"></a>};
<a name="line1520"></a>
<a name="line1521"></a>
<a name="line1522"></a>/**
<a name="line1523"></a> * Finds the first descendant node that matches the filter function, using
<a name="line1524"></a> * a depth first search. This function offers the most general purpose way
<a name="line1525"></a> * of finding a matching element. You may also wish to consider
<a name="line1526"></a> * {@code goog.dom.query} which can express many matching criteria using
<a name="line1527"></a> * CSS selector expressions. These expressions often result in a more
<a name="line1528"></a> * compact representation of the desired result.
<a name="line1529"></a> * @see goog.dom.query
<a name="line1530"></a> *
<a name="line1531"></a> * @param {Node} root The root of the tree to search.
<a name="line1532"></a> * @param {function(Node) : boolean} p The filter function.
<a name="line1533"></a> * @return {Node|undefined} The found node or undefined if none is found.
<a name="line1534"></a> */
<a name="line1535"></a>goog.dom.findNode = function(root, p) {
<a name="line1536"></a>  var rv = [];
<a name="line1537"></a>  var found = goog.dom.findNodes_(root, p, rv, true);
<a name="line1538"></a>  return found ? rv[0] : undefined;
<a name="line1539"></a>};
<a name="line1540"></a>
<a name="line1541"></a>
<a name="line1542"></a>/**
<a name="line1543"></a> * Finds all the descendant nodes that match the filter function, using a
<a name="line1544"></a> * a depth first search. This function offers the most general-purpose way
<a name="line1545"></a> * of finding a set of matching elements. You may also wish to consider
<a name="line1546"></a> * {@code goog.dom.query} which can express many matching criteria using
<a name="line1547"></a> * CSS selector expressions. These expressions often result in a more
<a name="line1548"></a> * compact representation of the desired result.
<a name="line1549"></a>
<a name="line1550"></a> * @param {Node} root The root of the tree to search.
<a name="line1551"></a> * @param {function(Node) : boolean} p The filter function.
<a name="line1552"></a> * @return {!Array.&lt;!Node&gt;} The found nodes or an empty array if none are found.
<a name="line1553"></a> */
<a name="line1554"></a>goog.dom.findNodes = function(root, p) {
<a name="line1555"></a>  var rv = [];
<a name="line1556"></a>  goog.dom.findNodes_(root, p, rv, false);
<a name="line1557"></a>  return rv;
<a name="line1558"></a>};
<a name="line1559"></a>
<a name="line1560"></a>
<a name="line1561"></a>/**
<a name="line1562"></a> * Finds the first or all the descendant nodes that match the filter function,
<a name="line1563"></a> * using a depth first search.
<a name="line1564"></a> * @param {Node} root The root of the tree to search.
<a name="line1565"></a> * @param {function(Node) : boolean} p The filter function.
<a name="line1566"></a> * @param {!Array.&lt;!Node&gt;} rv The found nodes are added to this array.
<a name="line1567"></a> * @param {boolean} findOne If true we exit after the first found node.
<a name="line1568"></a> * @return {boolean} Whether the search is complete or not. True in case findOne
<a name="line1569"></a> *     is true and the node is found. False otherwise.
<a name="line1570"></a> * @private
<a name="line1571"></a> */
<a name="line1572"></a>goog.dom.findNodes_ = function(root, p, rv, findOne) {
<a name="line1573"></a>  if (root != null) {
<a name="line1574"></a>    var child = root.firstChild;
<a name="line1575"></a>    while (child) {
<a name="line1576"></a>      if (p(child)) {
<a name="line1577"></a>        rv.push(child);
<a name="line1578"></a>        if (findOne) {
<a name="line1579"></a>          return true;
<a name="line1580"></a>        }
<a name="line1581"></a>      }
<a name="line1582"></a>      if (goog.dom.findNodes_(child, p, rv, findOne)) {
<a name="line1583"></a>        return true;
<a name="line1584"></a>      }
<a name="line1585"></a>      child = child.nextSibling;
<a name="line1586"></a>    }
<a name="line1587"></a>  }
<a name="line1588"></a>  return false;
<a name="line1589"></a>};
<a name="line1590"></a>
<a name="line1591"></a>
<a name="line1592"></a>/**
<a name="line1593"></a> * Map of tags whose content to ignore when calculating text length.
<a name="line1594"></a> * @type {Object}
<a name="line1595"></a> * @private
<a name="line1596"></a> */
<a name="line1597"></a>goog.dom.TAGS_TO_IGNORE_ = {
<a name="line1598"></a>  &#39;SCRIPT&#39;: 1,
<a name="line1599"></a>  &#39;STYLE&#39;: 1,
<a name="line1600"></a>  &#39;HEAD&#39;: 1,
<a name="line1601"></a>  &#39;IFRAME&#39;: 1,
<a name="line1602"></a>  &#39;OBJECT&#39;: 1
<a name="line1603"></a>};
<a name="line1604"></a>
<a name="line1605"></a>
<a name="line1606"></a>/**
<a name="line1607"></a> * Map of tags which have predefined values with regard to whitespace.
<a name="line1608"></a> * @type {Object}
<a name="line1609"></a> * @private
<a name="line1610"></a> */
<a name="line1611"></a>goog.dom.PREDEFINED_TAG_VALUES_ = {&#39;IMG&#39;: &#39; &#39;, &#39;BR&#39;: &#39;\n&#39;};
<a name="line1612"></a>
<a name="line1613"></a>
<a name="line1614"></a>/**
<a name="line1615"></a> * Returns true if the element has a tab index that allows it to receive
<a name="line1616"></a> * keyboard focus (tabIndex &gt;= 0), false otherwise.  Note that form elements
<a name="line1617"></a> * natively support keyboard focus, even if they have no tab index.
<a name="line1618"></a> * @param {Element} element Element to check.
<a name="line1619"></a> * @return {boolean} Whether the element has a tab index that allows keyboard
<a name="line1620"></a> *     focus.
<a name="line1621"></a> * @see http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
<a name="line1622"></a> */
<a name="line1623"></a>goog.dom.isFocusableTabIndex = function(element) {
<a name="line1624"></a>  // IE returns 0 for an unset tabIndex, so we must use getAttributeNode(),
<a name="line1625"></a>  // which returns an object with a &#39;specified&#39; property if tabIndex is
<a name="line1626"></a>  // specified.  This works on other browsers, too.
<a name="line1627"></a>  var attrNode = element.getAttributeNode(&#39;tabindex&#39;); // Must be lowercase!
<a name="line1628"></a>  if (attrNode &amp;&amp; attrNode.specified) {
<a name="line1629"></a>    var index = element.tabIndex;
<a name="line1630"></a>    // NOTE: IE9 puts tabIndex in 16-bit int, e.g. -2 is 65534.
<a name="line1631"></a>    return goog.isNumber(index) &amp;&amp; index &gt;= 0 &amp;&amp; index &lt; 32768;
<a name="line1632"></a>  }
<a name="line1633"></a>  return false;
<a name="line1634"></a>};
<a name="line1635"></a>
<a name="line1636"></a>
<a name="line1637"></a>/**
<a name="line1638"></a> * Enables or disables keyboard focus support on the element via its tab index.
<a name="line1639"></a> * Only elements for which {@link goog.dom.isFocusableTabIndex} returns true
<a name="line1640"></a> * (or elements that natively support keyboard focus, like form elements) can
<a name="line1641"></a> * receive keyboard focus.  See http://go/tabindex for more info.
<a name="line1642"></a> * @param {Element} element Element whose tab index is to be changed.
<a name="line1643"></a> * @param {boolean} enable Whether to set or remove a tab index on the element
<a name="line1644"></a> *     that supports keyboard focus.
<a name="line1645"></a> */
<a name="line1646"></a>goog.dom.setFocusableTabIndex = function(element, enable) {
<a name="line1647"></a>  if (enable) {
<a name="line1648"></a>    element.tabIndex = 0;
<a name="line1649"></a>  } else {
<a name="line1650"></a>    // Set tabIndex to -1 first, then remove it. This is a workaround for
<a name="line1651"></a>    // Safari (confirmed in version 4 on Windows). When removing the attribute
<a name="line1652"></a>    // without setting it to -1 first, the element remains keyboard focusable
<a name="line1653"></a>    // despite not having a tabIndex attribute anymore.
<a name="line1654"></a>    element.tabIndex = -1;
<a name="line1655"></a>    element.removeAttribute(&#39;tabIndex&#39;); // Must be camelCase!
<a name="line1656"></a>  }
<a name="line1657"></a>};
<a name="line1658"></a>
<a name="line1659"></a>
<a name="line1660"></a>/**
<a name="line1661"></a> * Returns the text content of the current node, without markup and invisible
<a name="line1662"></a> * symbols. New lines are stripped and whitespace is collapsed,
<a name="line1663"></a> * such that each character would be visible.
<a name="line1664"></a> *
<a name="line1665"></a> * In browsers that support it, innerText is used.  Other browsers attempt to
<a name="line1666"></a> * simulate it via node traversal.  Line breaks are canonicalized in IE.
<a name="line1667"></a> *
<a name="line1668"></a> * @param {Node} node The node from which we are getting content.
<a name="line1669"></a> * @return {string} The text content.
<a name="line1670"></a> */
<a name="line1671"></a>goog.dom.getTextContent = function(node) {
<a name="line1672"></a>  var textContent;
<a name="line1673"></a>  // Note(arv): IE9, Opera, and Safari 3 support innerText but they include
<a name="line1674"></a>  // text nodes in script tags. So we revert to use a user agent test here.
<a name="line1675"></a>  if (goog.dom.BrowserFeature.CAN_USE_INNER_TEXT &amp;&amp; (&#39;innerText&#39; in node)) {
<a name="line1676"></a>    textContent = goog.string.canonicalizeNewlines(node.innerText);
<a name="line1677"></a>    // Unfortunately .innerText() returns text with &amp;shy; symbols
<a name="line1678"></a>    // We need to filter it out and then remove duplicate whitespaces
<a name="line1679"></a>  } else {
<a name="line1680"></a>    var buf = [];
<a name="line1681"></a>    goog.dom.getTextContent_(node, buf, true);
<a name="line1682"></a>    textContent = buf.join(&#39;&#39;);
<a name="line1683"></a>  }
<a name="line1684"></a>
<a name="line1685"></a>  // Strip &amp;shy; entities. goog.format.insertWordBreaks inserts them in Opera.
<a name="line1686"></a>  textContent = textContent.replace(/ \xAD /g, &#39; &#39;).replace(/\xAD/g, &#39;&#39;);
<a name="line1687"></a>  // Strip &amp;#8203; entities. goog.format.insertWordBreaks inserts them in IE8.
<a name="line1688"></a>  textContent = textContent.replace(/\u200B/g, &#39;&#39;);
<a name="line1689"></a>
<a name="line1690"></a>  // Skip this replacement on old browsers with working innerText, which
<a name="line1691"></a>  // automatically turns &amp;nbsp; into &#39; &#39; and / +/ into &#39; &#39; when reading
<a name="line1692"></a>  // innerText.
<a name="line1693"></a>  if (!goog.dom.BrowserFeature.CAN_USE_INNER_TEXT) {
<a name="line1694"></a>    textContent = textContent.replace(/ +/g, &#39; &#39;);
<a name="line1695"></a>  }
<a name="line1696"></a>  if (textContent != &#39; &#39;) {
<a name="line1697"></a>    textContent = textContent.replace(/^\s*/, &#39;&#39;);
<a name="line1698"></a>  }
<a name="line1699"></a>
<a name="line1700"></a>  return textContent;
<a name="line1701"></a>};
<a name="line1702"></a>
<a name="line1703"></a>
<a name="line1704"></a>/**
<a name="line1705"></a> * Returns the text content of the current node, without markup.
<a name="line1706"></a> *
<a name="line1707"></a> * Unlike {@code getTextContent} this method does not collapse whitespaces
<a name="line1708"></a> * or normalize lines breaks.
<a name="line1709"></a> *
<a name="line1710"></a> * @param {Node} node The node from which we are getting content.
<a name="line1711"></a> * @return {string} The raw text content.
<a name="line1712"></a> */
<a name="line1713"></a>goog.dom.getRawTextContent = function(node) {
<a name="line1714"></a>  var buf = [];
<a name="line1715"></a>  goog.dom.getTextContent_(node, buf, false);
<a name="line1716"></a>
<a name="line1717"></a>  return buf.join(&#39;&#39;);
<a name="line1718"></a>};
<a name="line1719"></a>
<a name="line1720"></a>
<a name="line1721"></a>/**
<a name="line1722"></a> * Recursive support function for text content retrieval.
<a name="line1723"></a> *
<a name="line1724"></a> * @param {Node} node The node from which we are getting content.
<a name="line1725"></a> * @param {Array} buf string buffer.
<a name="line1726"></a> * @param {boolean} normalizeWhitespace Whether to normalize whitespace.
<a name="line1727"></a> * @private
<a name="line1728"></a> */
<a name="line1729"></a>goog.dom.getTextContent_ = function(node, buf, normalizeWhitespace) {
<a name="line1730"></a>  if (node.nodeName in goog.dom.TAGS_TO_IGNORE_) {
<a name="line1731"></a>    // ignore certain tags
<a name="line1732"></a>  } else if (node.nodeType == goog.dom.NodeType.TEXT) {
<a name="line1733"></a>    if (normalizeWhitespace) {
<a name="line1734"></a>      buf.push(String(node.nodeValue).replace(/(\r\n|\r|\n)/g, &#39;&#39;));
<a name="line1735"></a>    } else {
<a name="line1736"></a>      buf.push(node.nodeValue);
<a name="line1737"></a>    }
<a name="line1738"></a>  } else if (node.nodeName in goog.dom.PREDEFINED_TAG_VALUES_) {
<a name="line1739"></a>    buf.push(goog.dom.PREDEFINED_TAG_VALUES_[node.nodeName]);
<a name="line1740"></a>  } else {
<a name="line1741"></a>    var child = node.firstChild;
<a name="line1742"></a>    while (child) {
<a name="line1743"></a>      goog.dom.getTextContent_(child, buf, normalizeWhitespace);
<a name="line1744"></a>      child = child.nextSibling;
<a name="line1745"></a>    }
<a name="line1746"></a>  }
<a name="line1747"></a>};
<a name="line1748"></a>
<a name="line1749"></a>
<a name="line1750"></a>/**
<a name="line1751"></a> * Returns the text length of the text contained in a node, without markup. This
<a name="line1752"></a> * is equivalent to the selection length if the node was selected, or the number
<a name="line1753"></a> * of cursor movements to traverse the node. Images &amp; BRs take one space.  New
<a name="line1754"></a> * lines are ignored.
<a name="line1755"></a> *
<a name="line1756"></a> * @param {Node} node The node whose text content length is being calculated.
<a name="line1757"></a> * @return {number} The length of {@code node}&#39;s text content.
<a name="line1758"></a> */
<a name="line1759"></a>goog.dom.getNodeTextLength = function(node) {
<a name="line1760"></a>  return goog.dom.getTextContent(node).length;
<a name="line1761"></a>};
<a name="line1762"></a>
<a name="line1763"></a>
<a name="line1764"></a>/**
<a name="line1765"></a> * Returns the text offset of a node relative to one of its ancestors. The text
<a name="line1766"></a> * length is the same as the length calculated by goog.dom.getNodeTextLength.
<a name="line1767"></a> *
<a name="line1768"></a> * @param {Node} node The node whose offset is being calculated.
<a name="line1769"></a> * @param {Node=} opt_offsetParent The node relative to which the offset will
<a name="line1770"></a> *     be calculated. Defaults to the node&#39;s owner document&#39;s body.
<a name="line1771"></a> * @return {number} The text offset.
<a name="line1772"></a> */
<a name="line1773"></a>goog.dom.getNodeTextOffset = function(node, opt_offsetParent) {
<a name="line1774"></a>  var root = opt_offsetParent || goog.dom.getOwnerDocument(node).body;
<a name="line1775"></a>  var buf = [];
<a name="line1776"></a>  while (node &amp;&amp; node != root) {
<a name="line1777"></a>    var cur = node;
<a name="line1778"></a>    while ((cur = cur.previousSibling)) {
<a name="line1779"></a>      buf.unshift(goog.dom.getTextContent(cur));
<a name="line1780"></a>    }
<a name="line1781"></a>    node = node.parentNode;
<a name="line1782"></a>  }
<a name="line1783"></a>  // Trim left to deal with FF cases when there might be line breaks and empty
<a name="line1784"></a>  // nodes at the front of the text
<a name="line1785"></a>  return goog.string.trimLeft(buf.join(&#39;&#39;)).replace(/ +/g, &#39; &#39;).length;
<a name="line1786"></a>};
<a name="line1787"></a>
<a name="line1788"></a>
<a name="line1789"></a>/**
<a name="line1790"></a> * Returns the node at a given offset in a parent node.  If an object is
<a name="line1791"></a> * provided for the optional third parameter, the node and the remainder of the
<a name="line1792"></a> * offset will stored as properties of this object.
<a name="line1793"></a> * @param {Node} parent The parent node.
<a name="line1794"></a> * @param {number} offset The offset into the parent node.
<a name="line1795"></a> * @param {Object=} opt_result Object to be used to store the return value. The
<a name="line1796"></a> *     return value will be stored in the form {node: Node, remainder: number}
<a name="line1797"></a> *     if this object is provided.
<a name="line1798"></a> * @return {Node} The node at the given offset.
<a name="line1799"></a> */
<a name="line1800"></a>goog.dom.getNodeAtOffset = function(parent, offset, opt_result) {
<a name="line1801"></a>  var stack = [parent], pos = 0, cur = null;
<a name="line1802"></a>  while (stack.length &gt; 0 &amp;&amp; pos &lt; offset) {
<a name="line1803"></a>    cur = stack.pop();
<a name="line1804"></a>    if (cur.nodeName in goog.dom.TAGS_TO_IGNORE_) {
<a name="line1805"></a>      // ignore certain tags
<a name="line1806"></a>    } else if (cur.nodeType == goog.dom.NodeType.TEXT) {
<a name="line1807"></a>      var text = cur.nodeValue.replace(/(\r\n|\r|\n)/g, &#39;&#39;).replace(/ +/g, &#39; &#39;);
<a name="line1808"></a>      pos += text.length;
<a name="line1809"></a>    } else if (cur.nodeName in goog.dom.PREDEFINED_TAG_VALUES_) {
<a name="line1810"></a>      pos += goog.dom.PREDEFINED_TAG_VALUES_[cur.nodeName].length;
<a name="line1811"></a>    } else {
<a name="line1812"></a>      for (var i = cur.childNodes.length - 1; i &gt;= 0; i--) {
<a name="line1813"></a>        stack.push(cur.childNodes[i]);
<a name="line1814"></a>      }
<a name="line1815"></a>    }
<a name="line1816"></a>  }
<a name="line1817"></a>  if (goog.isObject(opt_result)) {
<a name="line1818"></a>    opt_result.remainder = cur ? cur.nodeValue.length + offset - pos - 1 : 0;
<a name="line1819"></a>    opt_result.node = cur;
<a name="line1820"></a>  }
<a name="line1821"></a>
<a name="line1822"></a>  return cur;
<a name="line1823"></a>};
<a name="line1824"></a>
<a name="line1825"></a>
<a name="line1826"></a>/**
<a name="line1827"></a> * Returns true if the object is a {@code NodeList}.  To qualify as a NodeList,
<a name="line1828"></a> * the object must have a numeric length property and an item function (which
<a name="line1829"></a> * has type &#39;string&#39; on IE for some reason).
<a name="line1830"></a> * @param {Object} val Object to test.
<a name="line1831"></a> * @return {boolean} Whether the object is a NodeList.
<a name="line1832"></a> */
<a name="line1833"></a>goog.dom.isNodeList = function(val) {
<a name="line1834"></a>  // TODO(attila): Now the isNodeList is part of goog.dom we can use
<a name="line1835"></a>  // goog.userAgent to make this simpler.
<a name="line1836"></a>  // A NodeList must have a length property of type &#39;number&#39; on all platforms.
<a name="line1837"></a>  if (val &amp;&amp; typeof val.length == &#39;number&#39;) {
<a name="line1838"></a>    // A NodeList is an object everywhere except Safari, where it&#39;s a function.
<a name="line1839"></a>    if (goog.isObject(val)) {
<a name="line1840"></a>      // A NodeList must have an item function (on non-IE platforms) or an item
<a name="line1841"></a>      // property of type &#39;string&#39; (on IE).
<a name="line1842"></a>      return typeof val.item == &#39;function&#39; || typeof val.item == &#39;string&#39;;
<a name="line1843"></a>    } else if (goog.isFunction(val)) {
<a name="line1844"></a>      // On Safari, a NodeList is a function with an item property that is also
<a name="line1845"></a>      // a function.
<a name="line1846"></a>      return typeof val.item == &#39;function&#39;;
<a name="line1847"></a>    }
<a name="line1848"></a>  }
<a name="line1849"></a>
<a name="line1850"></a>  // Not a NodeList.
<a name="line1851"></a>  return false;
<a name="line1852"></a>};
<a name="line1853"></a>
<a name="line1854"></a>
<a name="line1855"></a>/**
<a name="line1856"></a> * Walks up the DOM hierarchy returning the first ancestor that has the passed
<a name="line1857"></a> * tag name and/or class name. If the passed element matches the specified
<a name="line1858"></a> * criteria, the element itself is returned.
<a name="line1859"></a> * @param {Node} element The DOM node to start with.
<a name="line1860"></a> * @param {?(goog.dom.TagName|string)=} opt_tag The tag name to match (or
<a name="line1861"></a> *     null/undefined to match only based on class name).
<a name="line1862"></a> * @param {?string=} opt_class The class name to match (or null/undefined to
<a name="line1863"></a> *     match only based on tag name).
<a name="line1864"></a> * @return {Element} The first ancestor that matches the passed criteria, or
<a name="line1865"></a> *     null if no match is found.
<a name="line1866"></a> */
<a name="line1867"></a>goog.dom.getAncestorByTagNameAndClass = function(element, opt_tag, opt_class) {
<a name="line1868"></a>  if (!opt_tag &amp;&amp; !opt_class) {
<a name="line1869"></a>    return null;
<a name="line1870"></a>  }
<a name="line1871"></a>  var tagName = opt_tag ? opt_tag.toUpperCase() : null;
<a name="line1872"></a>  return /** @type {Element} */ (goog.dom.getAncestor(element,
<a name="line1873"></a>      function(node) {
<a name="line1874"></a>        return (!tagName || node.nodeName == tagName) &amp;&amp;
<a name="line1875"></a>               (!opt_class || goog.dom.classes.has(node, opt_class));
<a name="line1876"></a>      }, true));
<a name="line1877"></a>};
<a name="line1878"></a>
<a name="line1879"></a>
<a name="line1880"></a>/**
<a name="line1881"></a> * Walks up the DOM hierarchy returning the first ancestor that has the passed
<a name="line1882"></a> * class name. If the passed element matches the specified criteria, the
<a name="line1883"></a> * element itself is returned.
<a name="line1884"></a> * @param {Node} element The DOM node to start with.
<a name="line1885"></a> * @param {string} className The class name to match.
<a name="line1886"></a> * @return {Element} The first ancestor that matches the passed criteria, or
<a name="line1887"></a> *     null if none match.
<a name="line1888"></a> */
<a name="line1889"></a>goog.dom.getAncestorByClass = function(element, className) {
<a name="line1890"></a>  return goog.dom.getAncestorByTagNameAndClass(element, null, className);
<a name="line1891"></a>};
<a name="line1892"></a>
<a name="line1893"></a>
<a name="line1894"></a>/**
<a name="line1895"></a> * Walks up the DOM hierarchy returning the first ancestor that passes the
<a name="line1896"></a> * matcher function.
<a name="line1897"></a> * @param {Node} element The DOM node to start with.
<a name="line1898"></a> * @param {function(Node) : boolean} matcher A function that returns true if the
<a name="line1899"></a> *     passed node matches the desired criteria.
<a name="line1900"></a> * @param {boolean=} opt_includeNode If true, the node itself is included in
<a name="line1901"></a> *     the search (the first call to the matcher will pass startElement as
<a name="line1902"></a> *     the node to test).
<a name="line1903"></a> * @param {number=} opt_maxSearchSteps Maximum number of levels to search up the
<a name="line1904"></a> *     dom.
<a name="line1905"></a> * @return {Node} DOM node that matched the matcher, or null if there was
<a name="line1906"></a> *     no match.
<a name="line1907"></a> */
<a name="line1908"></a>goog.dom.getAncestor = function(
<a name="line1909"></a>    element, matcher, opt_includeNode, opt_maxSearchSteps) {
<a name="line1910"></a>  if (!opt_includeNode) {
<a name="line1911"></a>    element = element.parentNode;
<a name="line1912"></a>  }
<a name="line1913"></a>  var ignoreSearchSteps = opt_maxSearchSteps == null;
<a name="line1914"></a>  var steps = 0;
<a name="line1915"></a>  while (element &amp;&amp; (ignoreSearchSteps || steps &lt;= opt_maxSearchSteps)) {
<a name="line1916"></a>    if (matcher(element)) {
<a name="line1917"></a>      return element;
<a name="line1918"></a>    }
<a name="line1919"></a>    element = element.parentNode;
<a name="line1920"></a>    steps++;
<a name="line1921"></a>  }
<a name="line1922"></a>  // Reached the root of the DOM without a match
<a name="line1923"></a>  return null;
<a name="line1924"></a>};
<a name="line1925"></a>
<a name="line1926"></a>
<a name="line1927"></a>/**
<a name="line1928"></a> * Determines the active element in the given document.
<a name="line1929"></a> * @param {Document} doc The document to look in.
<a name="line1930"></a> * @return {Element} The active element.
<a name="line1931"></a> */
<a name="line1932"></a>goog.dom.getActiveElement = function(doc) {
<a name="line1933"></a>  try {
<a name="line1934"></a>    return doc &amp;&amp; doc.activeElement;
<a name="line1935"></a>  } catch (e) {
<a name="line1936"></a>    // NOTE(nicksantos): Sometimes, evaluating document.activeElement in IE
<a name="line1937"></a>    // throws an exception. I&#39;m not 100% sure why, but I suspect it chokes
<a name="line1938"></a>    // on document.activeElement if the activeElement has been recently
<a name="line1939"></a>    // removed from the DOM by a JS operation.
<a name="line1940"></a>    //
<a name="line1941"></a>    // We assume that an exception here simply means
<a name="line1942"></a>    // &quot;there is no active element.&quot;
<a name="line1943"></a>  }
<a name="line1944"></a>
<a name="line1945"></a>  return null;
<a name="line1946"></a>};
<a name="line1947"></a>
<a name="line1948"></a>
<a name="line1949"></a>
<a name="line1950"></a>/**
<a name="line1951"></a> * Create an instance of a DOM helper with a new document object.
<a name="line1952"></a> * @param {Document=} opt_document Document object to associate with this
<a name="line1953"></a> *     DOM helper.
<a name="line1954"></a> * @constructor
<a name="line1955"></a> */
<a name="line1956"></a>goog.dom.DomHelper = function(opt_document) {
<a name="line1957"></a>  /**
<a name="line1958"></a>   * Reference to the document object to use
<a name="line1959"></a>   * @type {!Document}
<a name="line1960"></a>   * @private
<a name="line1961"></a>   */
<a name="line1962"></a>  this.document_ = opt_document || goog.global.document || document;
<a name="line1963"></a>};
<a name="line1964"></a>
<a name="line1965"></a>
<a name="line1966"></a>/**
<a name="line1967"></a> * Gets the dom helper object for the document where the element resides.
<a name="line1968"></a> * @param {Node=} opt_node If present, gets the DomHelper for this node.
<a name="line1969"></a> * @return {!goog.dom.DomHelper} The DomHelper.
<a name="line1970"></a> */
<a name="line1971"></a>goog.dom.DomHelper.prototype.getDomHelper = goog.dom.getDomHelper;
<a name="line1972"></a>
<a name="line1973"></a>
<a name="line1974"></a>/**
<a name="line1975"></a> * Sets the document object.
<a name="line1976"></a> * @param {!Document} document Document object.
<a name="line1977"></a> */
<a name="line1978"></a>goog.dom.DomHelper.prototype.setDocument = function(document) {
<a name="line1979"></a>  this.document_ = document;
<a name="line1980"></a>};
<a name="line1981"></a>
<a name="line1982"></a>
<a name="line1983"></a>/**
<a name="line1984"></a> * Gets the document object being used by the dom library.
<a name="line1985"></a> * @return {!Document} Document object.
<a name="line1986"></a> */
<a name="line1987"></a>goog.dom.DomHelper.prototype.getDocument = function() {
<a name="line1988"></a>  return this.document_;
<a name="line1989"></a>};
<a name="line1990"></a>
<a name="line1991"></a>
<a name="line1992"></a>/**
<a name="line1993"></a> * Alias for {@code getElementById}. If a DOM node is passed in then we just
<a name="line1994"></a> * return that.
<a name="line1995"></a> * @param {string|Element} element Element ID or a DOM node.
<a name="line1996"></a> * @return {Element} The element with the given ID, or the node passed in.
<a name="line1997"></a> */
<a name="line1998"></a>goog.dom.DomHelper.prototype.getElement = function(element) {
<a name="line1999"></a>  if (goog.isString(element)) {
<a name="line2000"></a>    return this.document_.getElementById(element);
<a name="line2001"></a>  } else {
<a name="line2002"></a>    return element;
<a name="line2003"></a>  }
<a name="line2004"></a>};
<a name="line2005"></a>
<a name="line2006"></a>
<a name="line2007"></a>/**
<a name="line2008"></a> * Alias for {@code getElement}.
<a name="line2009"></a> * @param {string|Element} element Element ID or a DOM node.
<a name="line2010"></a> * @return {Element} The element with the given ID, or the node passed in.
<a name="line2011"></a> * @deprecated Use {@link goog.dom.DomHelper.prototype.getElement} instead.
<a name="line2012"></a> */
<a name="line2013"></a>goog.dom.DomHelper.prototype.$ = goog.dom.DomHelper.prototype.getElement;
<a name="line2014"></a>
<a name="line2015"></a>
<a name="line2016"></a>/**
<a name="line2017"></a> * Looks up elements by both tag and class name, using browser native functions
<a name="line2018"></a> * ({@code querySelectorAll}, {@code getElementsByTagName} or
<a name="line2019"></a> * {@code getElementsByClassName}) where possible. The returned array is a live
<a name="line2020"></a> * NodeList or a static list depending on the code path taken.
<a name="line2021"></a> *
<a name="line2022"></a> * @see goog.dom.query
<a name="line2023"></a> *
<a name="line2024"></a> * @param {?string=} opt_tag Element tag name or * for all tags.
<a name="line2025"></a> * @param {?string=} opt_class Optional class name.
<a name="line2026"></a> * @param {(Document|Element)=} opt_el Optional element to look in.
<a name="line2027"></a> * @return { {length: number} } Array-like list of elements (only a length
<a name="line2028"></a> *     property and numerical indices are guaranteed to exist).
<a name="line2029"></a> */
<a name="line2030"></a>goog.dom.DomHelper.prototype.getElementsByTagNameAndClass = function(opt_tag,
<a name="line2031"></a>                                                                     opt_class,
<a name="line2032"></a>                                                                     opt_el) {
<a name="line2033"></a>  return goog.dom.getElementsByTagNameAndClass_(this.document_, opt_tag,
<a name="line2034"></a>                                                opt_class, opt_el);
<a name="line2035"></a>};
<a name="line2036"></a>
<a name="line2037"></a>
<a name="line2038"></a>/**
<a name="line2039"></a> * Returns an array of all the elements with the provided className.
<a name="line2040"></a> * @see {goog.dom.query}
<a name="line2041"></a> * @param {string} className the name of the class to look for.
<a name="line2042"></a> * @param {Element|Document=} opt_el Optional element to look in.
<a name="line2043"></a> * @return { {length: number} } The items found with the class name provided.
<a name="line2044"></a> */
<a name="line2045"></a>goog.dom.DomHelper.prototype.getElementsByClass = function(className, opt_el) {
<a name="line2046"></a>  var doc = opt_el || this.document_;
<a name="line2047"></a>  return goog.dom.getElementsByClass(className, doc);
<a name="line2048"></a>};
<a name="line2049"></a>
<a name="line2050"></a>
<a name="line2051"></a>/**
<a name="line2052"></a> * Returns the first element we find matching the provided class name.
<a name="line2053"></a> * @see {goog.dom.query}
<a name="line2054"></a> * @param {string} className the name of the class to look for.
<a name="line2055"></a> * @param {(Element|Document)=} opt_el Optional element to look in.
<a name="line2056"></a> * @return {Element} The first item found with the class name provided.
<a name="line2057"></a> */
<a name="line2058"></a>goog.dom.DomHelper.prototype.getElementByClass = function(className, opt_el) {
<a name="line2059"></a>  var doc = opt_el || this.document_;
<a name="line2060"></a>  return goog.dom.getElementByClass(className, doc);
<a name="line2061"></a>};
<a name="line2062"></a>
<a name="line2063"></a>
<a name="line2064"></a>/**
<a name="line2065"></a> * Alias for {@code getElementsByTagNameAndClass}.
<a name="line2066"></a> * @deprecated Use DomHelper getElementsByTagNameAndClass.
<a name="line2067"></a> * @see goog.dom.query
<a name="line2068"></a> *
<a name="line2069"></a> * @param {?string=} opt_tag Element tag name.
<a name="line2070"></a> * @param {?string=} opt_class Optional class name.
<a name="line2071"></a> * @param {Element=} opt_el Optional element to look in.
<a name="line2072"></a> * @return { {length: number} } Array-like list of elements (only a length
<a name="line2073"></a> *     property and numerical indices are guaranteed to exist).
<a name="line2074"></a> */
<a name="line2075"></a>goog.dom.DomHelper.prototype.$$ =
<a name="line2076"></a>    goog.dom.DomHelper.prototype.getElementsByTagNameAndClass;
<a name="line2077"></a>
<a name="line2078"></a>
<a name="line2079"></a>/**
<a name="line2080"></a> * Sets a number of properties on a node.
<a name="line2081"></a> * @param {Element} element DOM node to set properties on.
<a name="line2082"></a> * @param {Object} properties Hash of property:value pairs.
<a name="line2083"></a> */
<a name="line2084"></a>goog.dom.DomHelper.prototype.setProperties = goog.dom.setProperties;
<a name="line2085"></a>
<a name="line2086"></a>
<a name="line2087"></a>/**
<a name="line2088"></a> * Gets the dimensions of the viewport.
<a name="line2089"></a> * @param {Window=} opt_window Optional window element to test. Defaults to
<a name="line2090"></a> *     the window of the Dom Helper.
<a name="line2091"></a> * @return {!goog.math.Size} Object with values &#39;width&#39; and &#39;height&#39;.
<a name="line2092"></a> */
<a name="line2093"></a>goog.dom.DomHelper.prototype.getViewportSize = function(opt_window) {
<a name="line2094"></a>  // TODO(arv): This should not take an argument. That breaks the rule of a
<a name="line2095"></a>  // a DomHelper representing a single frame/window/document.
<a name="line2096"></a>  return goog.dom.getViewportSize(opt_window || this.getWindow());
<a name="line2097"></a>};
<a name="line2098"></a>
<a name="line2099"></a>
<a name="line2100"></a>/**
<a name="line2101"></a> * Calculates the height of the document.
<a name="line2102"></a> *
<a name="line2103"></a> * @return {number} The height of the document.
<a name="line2104"></a> */
<a name="line2105"></a>goog.dom.DomHelper.prototype.getDocumentHeight = function() {
<a name="line2106"></a>  return goog.dom.getDocumentHeight_(this.getWindow());
<a name="line2107"></a>};
<a name="line2108"></a>
<a name="line2109"></a>
<a name="line2110"></a>/**
<a name="line2111"></a> * Typedef for use with goog.dom.createDom and goog.dom.append.
<a name="line2112"></a> * @typedef {Object|string|Array|NodeList}
<a name="line2113"></a> */
<a name="line2114"></a>goog.dom.Appendable;
<a name="line2115"></a>
<a name="line2116"></a>
<a name="line2117"></a>/**
<a name="line2118"></a> * Returns a dom node with a set of attributes.  This function accepts varargs
<a name="line2119"></a> * for subsequent nodes to be added.  Subsequent nodes will be added to the
<a name="line2120"></a> * first node as childNodes.
<a name="line2121"></a> *
<a name="line2122"></a> * So:
<a name="line2123"></a> * &lt;code&gt;createDom(&#39;div&#39;, null, createDom(&#39;p&#39;), createDom(&#39;p&#39;));&lt;/code&gt;
<a name="line2124"></a> * would return a div with two child paragraphs
<a name="line2125"></a> *
<a name="line2126"></a> * An easy way to move all child nodes of an existing element to a new parent
<a name="line2127"></a> * element is:
<a name="line2128"></a> * &lt;code&gt;createDom(&#39;div&#39;, null, oldElement.childNodes);&lt;/code&gt;
<a name="line2129"></a> * which will remove all child nodes from the old element and add them as
<a name="line2130"></a> * child nodes of the new DIV.
<a name="line2131"></a> *
<a name="line2132"></a> * @param {string} tagName Tag to create.
<a name="line2133"></a> * @param {Object|string=} opt_attributes If object, then a map of name-value
<a name="line2134"></a> *     pairs for attributes. If a string, then this is the className of the new
<a name="line2135"></a> *     element.
<a name="line2136"></a> * @param {...goog.dom.Appendable} var_args Further DOM nodes or
<a name="line2137"></a> *     strings for text nodes. If one of the var_args is an array or
<a name="line2138"></a> *     NodeList, its elements will be added as childNodes instead.
<a name="line2139"></a> * @return {!Element} Reference to a DOM node.
<a name="line2140"></a> */
<a name="line2141"></a>goog.dom.DomHelper.prototype.createDom = function(tagName,
<a name="line2142"></a>                                                  opt_attributes,
<a name="line2143"></a>                                                  var_args) {
<a name="line2144"></a>  return goog.dom.createDom_(this.document_, arguments);
<a name="line2145"></a>};
<a name="line2146"></a>
<a name="line2147"></a>
<a name="line2148"></a>/**
<a name="line2149"></a> * Alias for {@code createDom}.
<a name="line2150"></a> * @param {string} tagName Tag to create.
<a name="line2151"></a> * @param {(Object|string)=} opt_attributes If object, then a map of name-value
<a name="line2152"></a> *     pairs for attributes. If a string, then this is the className of the new
<a name="line2153"></a> *     element.
<a name="line2154"></a> * @param {...goog.dom.Appendable} var_args Further DOM nodes or strings for
<a name="line2155"></a> *     text nodes.  If one of the var_args is an array, its children will be
<a name="line2156"></a> *     added as childNodes instead.
<a name="line2157"></a> * @return {!Element} Reference to a DOM node.
<a name="line2158"></a> * @deprecated Use {@link goog.dom.DomHelper.prototype.createDom} instead.
<a name="line2159"></a> */
<a name="line2160"></a>goog.dom.DomHelper.prototype.$dom = goog.dom.DomHelper.prototype.createDom;
<a name="line2161"></a>
<a name="line2162"></a>
<a name="line2163"></a>/**
<a name="line2164"></a> * Creates a new element.
<a name="line2165"></a> * @param {string} name Tag name.
<a name="line2166"></a> * @return {!Element} The new element.
<a name="line2167"></a> */
<a name="line2168"></a>goog.dom.DomHelper.prototype.createElement = function(name) {
<a name="line2169"></a>  return this.document_.createElement(name);
<a name="line2170"></a>};
<a name="line2171"></a>
<a name="line2172"></a>
<a name="line2173"></a>/**
<a name="line2174"></a> * Creates a new text node.
<a name="line2175"></a> * @param {number|string} content Content.
<a name="line2176"></a> * @return {!Text} The new text node.
<a name="line2177"></a> */
<a name="line2178"></a>goog.dom.DomHelper.prototype.createTextNode = function(content) {
<a name="line2179"></a>  return this.document_.createTextNode(String(content));
<a name="line2180"></a>};
<a name="line2181"></a>
<a name="line2182"></a>
<a name="line2183"></a>/**
<a name="line2184"></a> * Create a table.
<a name="line2185"></a> * @param {number} rows The number of rows in the table.  Must be &gt;= 1.
<a name="line2186"></a> * @param {number} columns The number of columns in the table.  Must be &gt;= 1.
<a name="line2187"></a> * @param {boolean=} opt_fillWithNbsp If true, fills table entries with nsbps.
<a name="line2188"></a> * @return {!Element} The created table.
<a name="line2189"></a> */
<a name="line2190"></a>goog.dom.DomHelper.prototype.createTable = function(rows, columns,
<a name="line2191"></a>    opt_fillWithNbsp) {
<a name="line2192"></a>  return goog.dom.createTable_(this.document_, rows, columns,
<a name="line2193"></a>      !!opt_fillWithNbsp);
<a name="line2194"></a>};
<a name="line2195"></a>
<a name="line2196"></a>
<a name="line2197"></a>/**
<a name="line2198"></a> * Converts an HTML string into a node or a document fragment.  A single Node
<a name="line2199"></a> * is used if the {@code htmlString} only generates a single node.  If the
<a name="line2200"></a> * {@code htmlString} generates multiple nodes then these are put inside a
<a name="line2201"></a> * {@code DocumentFragment}.
<a name="line2202"></a> *
<a name="line2203"></a> * @param {string} htmlString The HTML string to convert.
<a name="line2204"></a> * @return {!Node} The resulting node.
<a name="line2205"></a> */
<a name="line2206"></a>goog.dom.DomHelper.prototype.htmlToDocumentFragment = function(htmlString) {
<a name="line2207"></a>  return goog.dom.htmlToDocumentFragment_(this.document_, htmlString);
<a name="line2208"></a>};
<a name="line2209"></a>
<a name="line2210"></a>
<a name="line2211"></a>/**
<a name="line2212"></a> * Returns the compatMode of the document.
<a name="line2213"></a> * @return {string} The result is either CSS1Compat or BackCompat.
<a name="line2214"></a> * @deprecated use goog.dom.DomHelper.prototype.isCss1CompatMode instead.
<a name="line2215"></a> */
<a name="line2216"></a>goog.dom.DomHelper.prototype.getCompatMode = function() {
<a name="line2217"></a>  return this.isCss1CompatMode() ? &#39;CSS1Compat&#39; : &#39;BackCompat&#39;;
<a name="line2218"></a>};
<a name="line2219"></a>
<a name="line2220"></a>
<a name="line2221"></a>/**
<a name="line2222"></a> * Returns true if the browser is in &quot;CSS1-compatible&quot; (standards-compliant)
<a name="line2223"></a> * mode, false otherwise.
<a name="line2224"></a> * @return {boolean} True if in CSS1-compatible mode.
<a name="line2225"></a> */
<a name="line2226"></a>goog.dom.DomHelper.prototype.isCss1CompatMode = function() {
<a name="line2227"></a>  return goog.dom.isCss1CompatMode_(this.document_);
<a name="line2228"></a>};
<a name="line2229"></a>
<a name="line2230"></a>
<a name="line2231"></a>/**
<a name="line2232"></a> * Gets the window object associated with the document.
<a name="line2233"></a> * @return {!Window} The window associated with the given document.
<a name="line2234"></a> */
<a name="line2235"></a>goog.dom.DomHelper.prototype.getWindow = function() {
<a name="line2236"></a>  return goog.dom.getWindow_(this.document_);
<a name="line2237"></a>};
<a name="line2238"></a>
<a name="line2239"></a>
<a name="line2240"></a>/**
<a name="line2241"></a> * Gets the document scroll element.
<a name="line2242"></a> * @return {Element} Scrolling element.
<a name="line2243"></a> */
<a name="line2244"></a>goog.dom.DomHelper.prototype.getDocumentScrollElement = function() {
<a name="line2245"></a>  return goog.dom.getDocumentScrollElement_(this.document_);
<a name="line2246"></a>};
<a name="line2247"></a>
<a name="line2248"></a>
<a name="line2249"></a>/**
<a name="line2250"></a> * Gets the document scroll distance as a coordinate object.
<a name="line2251"></a> * @return {!goog.math.Coordinate} Object with properties &#39;x&#39; and &#39;y&#39;.
<a name="line2252"></a> */
<a name="line2253"></a>goog.dom.DomHelper.prototype.getDocumentScroll = function() {
<a name="line2254"></a>  return goog.dom.getDocumentScroll_(this.document_);
<a name="line2255"></a>};
<a name="line2256"></a>
<a name="line2257"></a>
<a name="line2258"></a>/**
<a name="line2259"></a> * Determines the active element in the given document.
<a name="line2260"></a> * @param {Document=} opt_doc The document to look in.
<a name="line2261"></a> * @return {Element} The active element.
<a name="line2262"></a> */
<a name="line2263"></a>goog.dom.DomHelper.prototype.getActiveElement = function(opt_doc) {
<a name="line2264"></a>  return goog.dom.getActiveElement(opt_doc || this.document_);
<a name="line2265"></a>};
<a name="line2266"></a>
<a name="line2267"></a>
<a name="line2268"></a>/**
<a name="line2269"></a> * Appends a child to a node.
<a name="line2270"></a> * @param {Node} parent Parent.
<a name="line2271"></a> * @param {Node} child Child.
<a name="line2272"></a> */
<a name="line2273"></a>goog.dom.DomHelper.prototype.appendChild = goog.dom.appendChild;
<a name="line2274"></a>
<a name="line2275"></a>
<a name="line2276"></a>/**
<a name="line2277"></a> * Appends a node with text or other nodes.
<a name="line2278"></a> * @param {!Node} parent The node to append nodes to.
<a name="line2279"></a> * @param {...goog.dom.Appendable} var_args The things to append to the node.
<a name="line2280"></a> *     If this is a Node it is appended as is.
<a name="line2281"></a> *     If this is a string then a text node is appended.
<a name="line2282"></a> *     If this is an array like object then fields 0 to length - 1 are appended.
<a name="line2283"></a> */
<a name="line2284"></a>goog.dom.DomHelper.prototype.append = goog.dom.append;
<a name="line2285"></a>
<a name="line2286"></a>
<a name="line2287"></a>/**
<a name="line2288"></a> * Determines if the given node can contain children, intended to be used for
<a name="line2289"></a> * HTML generation.
<a name="line2290"></a> *
<a name="line2291"></a> * @param {Node} node The node to check.
<a name="line2292"></a> * @return {boolean} Whether the node can contain children.
<a name="line2293"></a> */
<a name="line2294"></a>goog.dom.DomHelper.prototype.canHaveChildren = goog.dom.canHaveChildren;
<a name="line2295"></a>
<a name="line2296"></a>
<a name="line2297"></a>/**
<a name="line2298"></a> * Removes all the child nodes on a DOM node.
<a name="line2299"></a> * @param {Node} node Node to remove children from.
<a name="line2300"></a> */
<a name="line2301"></a>goog.dom.DomHelper.prototype.removeChildren = goog.dom.removeChildren;
<a name="line2302"></a>
<a name="line2303"></a>
<a name="line2304"></a>/**
<a name="line2305"></a> * Inserts a new node before an existing reference node (i.e., as the previous
<a name="line2306"></a> * sibling). If the reference node has no parent, then does nothing.
<a name="line2307"></a> * @param {Node} newNode Node to insert.
<a name="line2308"></a> * @param {Node} refNode Reference node to insert before.
<a name="line2309"></a> */
<a name="line2310"></a>goog.dom.DomHelper.prototype.insertSiblingBefore = goog.dom.insertSiblingBefore;
<a name="line2311"></a>
<a name="line2312"></a>
<a name="line2313"></a>/**
<a name="line2314"></a> * Inserts a new node after an existing reference node (i.e., as the next
<a name="line2315"></a> * sibling). If the reference node has no parent, then does nothing.
<a name="line2316"></a> * @param {Node} newNode Node to insert.
<a name="line2317"></a> * @param {Node} refNode Reference node to insert after.
<a name="line2318"></a> */
<a name="line2319"></a>goog.dom.DomHelper.prototype.insertSiblingAfter = goog.dom.insertSiblingAfter;
<a name="line2320"></a>
<a name="line2321"></a>
<a name="line2322"></a>/**
<a name="line2323"></a> * Insert a child at a given index. If index is larger than the number of child
<a name="line2324"></a> * nodes that the parent currently has, the node is inserted as the last child
<a name="line2325"></a> * node.
<a name="line2326"></a> * @param {Element} parent The element into which to insert the child.
<a name="line2327"></a> * @param {Node} child The element to insert.
<a name="line2328"></a> * @param {number} index The index at which to insert the new child node. Must
<a name="line2329"></a> *     not be negative.
<a name="line2330"></a> */
<a name="line2331"></a>goog.dom.DomHelper.prototype.insertChildAt = goog.dom.insertChildAt;
<a name="line2332"></a>
<a name="line2333"></a>
<a name="line2334"></a>/**
<a name="line2335"></a> * Removes a node from its parent.
<a name="line2336"></a> * @param {Node} node The node to remove.
<a name="line2337"></a> * @return {Node} The node removed if removed; else, null.
<a name="line2338"></a> */
<a name="line2339"></a>goog.dom.DomHelper.prototype.removeNode = goog.dom.removeNode;
<a name="line2340"></a>
<a name="line2341"></a>
<a name="line2342"></a>/**
<a name="line2343"></a> * Replaces a node in the DOM tree. Will do nothing if {@code oldNode} has no
<a name="line2344"></a> * parent.
<a name="line2345"></a> * @param {Node} newNode Node to insert.
<a name="line2346"></a> * @param {Node} oldNode Node to replace.
<a name="line2347"></a> */
<a name="line2348"></a>goog.dom.DomHelper.prototype.replaceNode = goog.dom.replaceNode;
<a name="line2349"></a>
<a name="line2350"></a>
<a name="line2351"></a>/**
<a name="line2352"></a> * Flattens an element. That is, removes it and replace it with its children.
<a name="line2353"></a> * @param {Element} element The element to flatten.
<a name="line2354"></a> * @return {Element|undefined} The original element, detached from the document
<a name="line2355"></a> *     tree, sans children, or undefined if the element was already not in the
<a name="line2356"></a> *     document.
<a name="line2357"></a> */
<a name="line2358"></a>goog.dom.DomHelper.prototype.flattenElement = goog.dom.flattenElement;
<a name="line2359"></a>
<a name="line2360"></a>
<a name="line2361"></a>/**
<a name="line2362"></a> * Returns an array containing just the element children of the given element.
<a name="line2363"></a> * @param {Element} element The element whose element children we want.
<a name="line2364"></a> * @return {!(Array|NodeList)} An array or array-like list of just the element
<a name="line2365"></a> *     children of the given element.
<a name="line2366"></a> */
<a name="line2367"></a>goog.dom.DomHelper.prototype.getChildren = goog.dom.getChildren;
<a name="line2368"></a>
<a name="line2369"></a>
<a name="line2370"></a>/**
<a name="line2371"></a> * Returns the first child node that is an element.
<a name="line2372"></a> * @param {Node} node The node to get the first child element of.
<a name="line2373"></a> * @return {Element} The first child node of {@code node} that is an element.
<a name="line2374"></a> */
<a name="line2375"></a>goog.dom.DomHelper.prototype.getFirstElementChild =
<a name="line2376"></a>    goog.dom.getFirstElementChild;
<a name="line2377"></a>
<a name="line2378"></a>
<a name="line2379"></a>/**
<a name="line2380"></a> * Returns the last child node that is an element.
<a name="line2381"></a> * @param {Node} node The node to get the last child element of.
<a name="line2382"></a> * @return {Element} The last child node of {@code node} that is an element.
<a name="line2383"></a> */
<a name="line2384"></a>goog.dom.DomHelper.prototype.getLastElementChild = goog.dom.getLastElementChild;
<a name="line2385"></a>
<a name="line2386"></a>
<a name="line2387"></a>/**
<a name="line2388"></a> * Returns the first next sibling that is an element.
<a name="line2389"></a> * @param {Node} node The node to get the next sibling element of.
<a name="line2390"></a> * @return {Element} The next sibling of {@code node} that is an element.
<a name="line2391"></a> */
<a name="line2392"></a>goog.dom.DomHelper.prototype.getNextElementSibling =
<a name="line2393"></a>    goog.dom.getNextElementSibling;
<a name="line2394"></a>
<a name="line2395"></a>
<a name="line2396"></a>/**
<a name="line2397"></a> * Returns the first previous sibling that is an element.
<a name="line2398"></a> * @param {Node} node The node to get the previous sibling element of.
<a name="line2399"></a> * @return {Element} The first previous sibling of {@code node} that is
<a name="line2400"></a> *     an element.
<a name="line2401"></a> */
<a name="line2402"></a>goog.dom.DomHelper.prototype.getPreviousElementSibling =
<a name="line2403"></a>    goog.dom.getPreviousElementSibling;
<a name="line2404"></a>
<a name="line2405"></a>
<a name="line2406"></a>/**
<a name="line2407"></a> * Returns the next node in source order from the given node.
<a name="line2408"></a> * @param {Node} node The node.
<a name="line2409"></a> * @return {Node} The next node in the DOM tree, or null if this was the last
<a name="line2410"></a> *     node.
<a name="line2411"></a> */
<a name="line2412"></a>goog.dom.DomHelper.prototype.getNextNode = goog.dom.getNextNode;
<a name="line2413"></a>
<a name="line2414"></a>
<a name="line2415"></a>/**
<a name="line2416"></a> * Returns the previous node in source order from the given node.
<a name="line2417"></a> * @param {Node} node The node.
<a name="line2418"></a> * @return {Node} The previous node in the DOM tree, or null if this was the
<a name="line2419"></a> *     first node.
<a name="line2420"></a> */
<a name="line2421"></a>goog.dom.DomHelper.prototype.getPreviousNode = goog.dom.getPreviousNode;
<a name="line2422"></a>
<a name="line2423"></a>
<a name="line2424"></a>/**
<a name="line2425"></a> * Whether the object looks like a DOM node.
<a name="line2426"></a> * @param {*} obj The object being tested for node likeness.
<a name="line2427"></a> * @return {boolean} Whether the object looks like a DOM node.
<a name="line2428"></a> */
<a name="line2429"></a>goog.dom.DomHelper.prototype.isNodeLike = goog.dom.isNodeLike;
<a name="line2430"></a>
<a name="line2431"></a>
<a name="line2432"></a>/**
<a name="line2433"></a> * Whether the object looks like an Element.
<a name="line2434"></a> * @param {*} obj The object being tested for Element likeness.
<a name="line2435"></a> * @return {boolean} Whether the object looks like an Element.
<a name="line2436"></a> */
<a name="line2437"></a>goog.dom.DomHelper.prototype.isElement = goog.dom.isElement;
<a name="line2438"></a>
<a name="line2439"></a>
<a name="line2440"></a>/**
<a name="line2441"></a> * Returns true if the specified value is a Window object. This includes the
<a name="line2442"></a> * global window for HTML pages, and iframe windows.
<a name="line2443"></a> * @param {*} obj Variable to test.
<a name="line2444"></a> * @return {boolean} Whether the variable is a window.
<a name="line2445"></a> */
<a name="line2446"></a>goog.dom.DomHelper.prototype.isWindow = goog.dom.isWindow;
<a name="line2447"></a>
<a name="line2448"></a>
<a name="line2449"></a>/**
<a name="line2450"></a> * Returns an element&#39;s parent, if it&#39;s an Element.
<a name="line2451"></a> * @param {Element} element The DOM element.
<a name="line2452"></a> * @return {Element} The parent, or null if not an Element.
<a name="line2453"></a> */
<a name="line2454"></a>goog.dom.DomHelper.prototype.getParentElement = goog.dom.getParentElement;
<a name="line2455"></a>
<a name="line2456"></a>
<a name="line2457"></a>/**
<a name="line2458"></a> * Whether a node contains another node.
<a name="line2459"></a> * @param {Node} parent The node that should contain the other node.
<a name="line2460"></a> * @param {Node} descendant The node to test presence of.
<a name="line2461"></a> * @return {boolean} Whether the parent node contains the descendent node.
<a name="line2462"></a> */
<a name="line2463"></a>goog.dom.DomHelper.prototype.contains = goog.dom.contains;
<a name="line2464"></a>
<a name="line2465"></a>
<a name="line2466"></a>/**
<a name="line2467"></a> * Compares the document order of two nodes, returning 0 if they are the same
<a name="line2468"></a> * node, a negative number if node1 is before node2, and a positive number if
<a name="line2469"></a> * node2 is before node1.  Note that we compare the order the tags appear in the
<a name="line2470"></a> * document so in the tree &lt;b&gt;&lt;i&gt;text&lt;/i&gt;&lt;/b&gt; the B node is considered to be
<a name="line2471"></a> * before the I node.
<a name="line2472"></a> *
<a name="line2473"></a> * @param {Node} node1 The first node to compare.
<a name="line2474"></a> * @param {Node} node2 The second node to compare.
<a name="line2475"></a> * @return {number} 0 if the nodes are the same node, a negative number if node1
<a name="line2476"></a> *     is before node2, and a positive number if node2 is before node1.
<a name="line2477"></a> */
<a name="line2478"></a>goog.dom.DomHelper.prototype.compareNodeOrder = goog.dom.compareNodeOrder;
<a name="line2479"></a>
<a name="line2480"></a>
<a name="line2481"></a>/**
<a name="line2482"></a> * Find the deepest common ancestor of the given nodes.
<a name="line2483"></a> * @param {...Node} var_args The nodes to find a common ancestor of.
<a name="line2484"></a> * @return {Node} The common ancestor of the nodes, or null if there is none.
<a name="line2485"></a> *     null will only be returned if two or more of the nodes are from different
<a name="line2486"></a> *     documents.
<a name="line2487"></a> */
<a name="line2488"></a>goog.dom.DomHelper.prototype.findCommonAncestor = goog.dom.findCommonAncestor;
<a name="line2489"></a>
<a name="line2490"></a>
<a name="line2491"></a>/**
<a name="line2492"></a> * Returns the owner document for a node.
<a name="line2493"></a> * @param {Node} node The node to get the document for.
<a name="line2494"></a> * @return {!Document} The document owning the node.
<a name="line2495"></a> */
<a name="line2496"></a>goog.dom.DomHelper.prototype.getOwnerDocument = goog.dom.getOwnerDocument;
<a name="line2497"></a>
<a name="line2498"></a>
<a name="line2499"></a>/**
<a name="line2500"></a> * Cross browser function for getting the document element of an iframe.
<a name="line2501"></a> * @param {Element} iframe Iframe element.
<a name="line2502"></a> * @return {!Document} The frame content document.
<a name="line2503"></a> */
<a name="line2504"></a>goog.dom.DomHelper.prototype.getFrameContentDocument =
<a name="line2505"></a>    goog.dom.getFrameContentDocument;
<a name="line2506"></a>
<a name="line2507"></a>
<a name="line2508"></a>/**
<a name="line2509"></a> * Cross browser function for getting the window of a frame or iframe.
<a name="line2510"></a> * @param {Element} frame Frame element.
<a name="line2511"></a> * @return {Window} The window associated with the given frame.
<a name="line2512"></a> */
<a name="line2513"></a>goog.dom.DomHelper.prototype.getFrameContentWindow =
<a name="line2514"></a>    goog.dom.getFrameContentWindow;
<a name="line2515"></a>
<a name="line2516"></a>
<a name="line2517"></a>/**
<a name="line2518"></a> * Cross browser function for setting the text content of an element.
<a name="line2519"></a> * @param {Element} element The element to change the text content of.
<a name="line2520"></a> * @param {string} text The string that should replace the current element
<a name="line2521"></a> *     content with.
<a name="line2522"></a> */
<a name="line2523"></a>goog.dom.DomHelper.prototype.setTextContent = goog.dom.setTextContent;
<a name="line2524"></a>
<a name="line2525"></a>
<a name="line2526"></a>/**
<a name="line2527"></a> * Gets the outerHTML of a node, which islike innerHTML, except that it
<a name="line2528"></a> * actually contains the HTML of the node itself.
<a name="line2529"></a> * @param {Element} element The element to get the HTML of.
<a name="line2530"></a> * @return {string} The outerHTML of the given element.
<a name="line2531"></a> */
<a name="line2532"></a>goog.dom.DomHelper.prototype.getOuterHtml = goog.dom.getOuterHtml;
<a name="line2533"></a>
<a name="line2534"></a>
<a name="line2535"></a>/**
<a name="line2536"></a> * Finds the first descendant node that matches the filter function. This does
<a name="line2537"></a> * a depth first search.
<a name="line2538"></a> * @param {Node} root The root of the tree to search.
<a name="line2539"></a> * @param {function(Node) : boolean} p The filter function.
<a name="line2540"></a> * @return {Node|undefined} The found node or undefined if none is found.
<a name="line2541"></a> */
<a name="line2542"></a>goog.dom.DomHelper.prototype.findNode = goog.dom.findNode;
<a name="line2543"></a>
<a name="line2544"></a>
<a name="line2545"></a>/**
<a name="line2546"></a> * Finds all the descendant nodes that matches the filter function. This does a
<a name="line2547"></a> * depth first search.
<a name="line2548"></a> * @param {Node} root The root of the tree to search.
<a name="line2549"></a> * @param {function(Node) : boolean} p The filter function.
<a name="line2550"></a> * @return {Array.&lt;Node&gt;} The found nodes or an empty array if none are found.
<a name="line2551"></a> */
<a name="line2552"></a>goog.dom.DomHelper.prototype.findNodes = goog.dom.findNodes;
<a name="line2553"></a>
<a name="line2554"></a>
<a name="line2555"></a>/**
<a name="line2556"></a> * Returns true if the element has a tab index that allows it to receive
<a name="line2557"></a> * keyboard focus (tabIndex &gt;= 0), false otherwise.  Note that form elements
<a name="line2558"></a> * natively support keyboard focus, even if they have no tab index.
<a name="line2559"></a> * @param {Element} element Element to check.
<a name="line2560"></a> * @return {boolean} Whether the element has a tab index that allows keyboard
<a name="line2561"></a> *     focus.
<a name="line2562"></a> */
<a name="line2563"></a>goog.dom.DomHelper.prototype.isFocusableTabIndex = goog.dom.isFocusableTabIndex;
<a name="line2564"></a>
<a name="line2565"></a>
<a name="line2566"></a>/**
<a name="line2567"></a> * Enables or disables keyboard focus support on the element via its tab index.
<a name="line2568"></a> * Only elements for which {@link goog.dom.isFocusableTabIndex} returns true
<a name="line2569"></a> * (or elements that natively support keyboard focus, like form elements) can
<a name="line2570"></a> * receive keyboard focus.  See http://go/tabindex for more info.
<a name="line2571"></a> * @param {Element} element Element whose tab index is to be changed.
<a name="line2572"></a> * @param {boolean} enable Whether to set or remove a tab index on the element
<a name="line2573"></a> *     that supports keyboard focus.
<a name="line2574"></a> */
<a name="line2575"></a>goog.dom.DomHelper.prototype.setFocusableTabIndex =
<a name="line2576"></a>    goog.dom.setFocusableTabIndex;
<a name="line2577"></a>
<a name="line2578"></a>
<a name="line2579"></a>/**
<a name="line2580"></a> * Returns the text contents of the current node, without markup. New lines are
<a name="line2581"></a> * stripped and whitespace is collapsed, such that each character would be
<a name="line2582"></a> * visible.
<a name="line2583"></a> *
<a name="line2584"></a> * In browsers that support it, innerText is used.  Other browsers attempt to
<a name="line2585"></a> * simulate it via node traversal.  Line breaks are canonicalized in IE.
<a name="line2586"></a> *
<a name="line2587"></a> * @param {Node} node The node from which we are getting content.
<a name="line2588"></a> * @return {string} The text content.
<a name="line2589"></a> */
<a name="line2590"></a>goog.dom.DomHelper.prototype.getTextContent = goog.dom.getTextContent;
<a name="line2591"></a>
<a name="line2592"></a>
<a name="line2593"></a>/**
<a name="line2594"></a> * Returns the text length of the text contained in a node, without markup. This
<a name="line2595"></a> * is equivalent to the selection length if the node was selected, or the number
<a name="line2596"></a> * of cursor movements to traverse the node. Images &amp; BRs take one space.  New
<a name="line2597"></a> * lines are ignored.
<a name="line2598"></a> *
<a name="line2599"></a> * @param {Node} node The node whose text content length is being calculated.
<a name="line2600"></a> * @return {number} The length of {@code node}&#39;s text content.
<a name="line2601"></a> */
<a name="line2602"></a>goog.dom.DomHelper.prototype.getNodeTextLength = goog.dom.getNodeTextLength;
<a name="line2603"></a>
<a name="line2604"></a>
<a name="line2605"></a>/**
<a name="line2606"></a> * Returns the text offset of a node relative to one of its ancestors. The text
<a name="line2607"></a> * length is the same as the length calculated by
<a name="line2608"></a> * {@code goog.dom.getNodeTextLength}.
<a name="line2609"></a> *
<a name="line2610"></a> * @param {Node} node The node whose offset is being calculated.
<a name="line2611"></a> * @param {Node=} opt_offsetParent Defaults to the node&#39;s owner document&#39;s body.
<a name="line2612"></a> * @return {number} The text offset.
<a name="line2613"></a> */
<a name="line2614"></a>goog.dom.DomHelper.prototype.getNodeTextOffset = goog.dom.getNodeTextOffset;
<a name="line2615"></a>
<a name="line2616"></a>
<a name="line2617"></a>/**
<a name="line2618"></a> * Returns the node at a given offset in a parent node.  If an object is
<a name="line2619"></a> * provided for the optional third parameter, the node and the remainder of the
<a name="line2620"></a> * offset will stored as properties of this object.
<a name="line2621"></a> * @param {Node} parent The parent node.
<a name="line2622"></a> * @param {number} offset The offset into the parent node.
<a name="line2623"></a> * @param {Object=} opt_result Object to be used to store the return value. The
<a name="line2624"></a> *     return value will be stored in the form {node: Node, remainder: number}
<a name="line2625"></a> *     if this object is provided.
<a name="line2626"></a> * @return {Node} The node at the given offset.
<a name="line2627"></a> */
<a name="line2628"></a>goog.dom.DomHelper.prototype.getNodeAtOffset = goog.dom.getNodeAtOffset;
<a name="line2629"></a>
<a name="line2630"></a>
<a name="line2631"></a>/**
<a name="line2632"></a> * Returns true if the object is a {@code NodeList}.  To qualify as a NodeList,
<a name="line2633"></a> * the object must have a numeric length property and an item function (which
<a name="line2634"></a> * has type &#39;string&#39; on IE for some reason).
<a name="line2635"></a> * @param {Object} val Object to test.
<a name="line2636"></a> * @return {boolean} Whether the object is a NodeList.
<a name="line2637"></a> */
<a name="line2638"></a>goog.dom.DomHelper.prototype.isNodeList = goog.dom.isNodeList;
<a name="line2639"></a>
<a name="line2640"></a>
<a name="line2641"></a>/**
<a name="line2642"></a> * Walks up the DOM hierarchy returning the first ancestor that has the passed
<a name="line2643"></a> * tag name and/or class name. If the passed element matches the specified
<a name="line2644"></a> * criteria, the element itself is returned.
<a name="line2645"></a> * @param {Node} element The DOM node to start with.
<a name="line2646"></a> * @param {?(goog.dom.TagName|string)=} opt_tag The tag name to match (or
<a name="line2647"></a> *     null/undefined to match only based on class name).
<a name="line2648"></a> * @param {?string=} opt_class The class name to match (or null/undefined to
<a name="line2649"></a> *     match only based on tag name).
<a name="line2650"></a> * @return {Element} The first ancestor that matches the passed criteria, or
<a name="line2651"></a> *     null if no match is found.
<a name="line2652"></a> */
<a name="line2653"></a>goog.dom.DomHelper.prototype.getAncestorByTagNameAndClass =
<a name="line2654"></a>    goog.dom.getAncestorByTagNameAndClass;
<a name="line2655"></a>
<a name="line2656"></a>
<a name="line2657"></a>/**
<a name="line2658"></a> * Walks up the DOM hierarchy returning the first ancestor that has the passed
<a name="line2659"></a> * class name. If the passed element matches the specified criteria, the
<a name="line2660"></a> * element itself is returned.
<a name="line2661"></a> * @param {Node} element The DOM node to start with.
<a name="line2662"></a> * @param {string} class The class name to match.
<a name="line2663"></a> * @return {Element} The first ancestor that matches the passed criteria, or
<a name="line2664"></a> *     null if none match.
<a name="line2665"></a> */
<a name="line2666"></a>goog.dom.DomHelper.prototype.getAncestorByClass =
<a name="line2667"></a>    goog.dom.getAncestorByClass;
<a name="line2668"></a>
<a name="line2669"></a>
<a name="line2670"></a>/**
<a name="line2671"></a> * Walks up the DOM hierarchy returning the first ancestor that passes the
<a name="line2672"></a> * matcher function.
<a name="line2673"></a> * @param {Node} element The DOM node to start with.
<a name="line2674"></a> * @param {function(Node) : boolean} matcher A function that returns true if the
<a name="line2675"></a> *     passed node matches the desired criteria.
<a name="line2676"></a> * @param {boolean=} opt_includeNode If true, the node itself is included in
<a name="line2677"></a> *     the search (the first call to the matcher will pass startElement as
<a name="line2678"></a> *     the node to test).
<a name="line2679"></a> * @param {number=} opt_maxSearchSteps Maximum number of levels to search up the
<a name="line2680"></a> *     dom.
<a name="line2681"></a> * @return {Node} DOM node that matched the matcher, or null if there was
<a name="line2682"></a> *     no match.
<a name="line2683"></a> */
<a name="line2684"></a>goog.dom.DomHelper.prototype.getAncestor = goog.dom.getAncestor;
</pre>


</body>
</html>
